Wipro Milestone 1 Coding Questions & Answers 2024 | Wipro Milestone 1 Coding Questions | Wipro Milestone 1 Coding Questions For Freshers | Wipro Milestone 1 Coding Questions For Experience
Wipro Milestone 1 Coding Questions & Answers 2024: Wipro will conduct the Coding Test for each hiring Process. Every year, they hire a lot of employees to their company to fill many positions. As of now, they going to hold the test for the Wipro Milestone 1 Coding. So aspirants who are going to attend this hiring process kindly check out the Wipro Milestone 1 Coding Questions & Answers before attending the process. It is very important for all the contenders to before good before the Test.
Wipro Milestone 3 Coding Questions & Answers |
Wipro Talent Next Milestone 4 Coding Questions |
Here we have provided the sample Wipro Milestone 1 Coding Questions & Answers for your preparation process. With the help of this preparation good on the coding test & score good marks. If you qualify in this round only you may continue to attend the selection process, so read the article properly to get detailed information about the Previous Coding Questions
QUESTIONS) Count set bits in an integer
Input
13
Solution:
PYTHON PROGRAM
SAMPLE 01
#include <bits/stdc++.h> using namespace std; int countSetBits(int n) { // base case if (n == 0) return 0; else // if last bit set add 1 else add 0 return (n & 1) + countSetBits(n >> 1); } // driver code int main() { int n = 13; // function calling cout << countSetBits(n); return 0; } SAMPLE 02
#include <bits/stdc++.h> using namespace std; int countSetBits(int n) { // base case if (n == 0) return 0; else // if last bit set add 1 else add 0 return (n & 1) + countSetBits(n >> 1); } // driver code int main() { int n = 13; // function calling cout << countSetBits(n); return 0; }
C++ PROGRAM
# Python3 implementation of recursive # approach to find the number of set # bits in binary representation of # positive integer n def countSetBits( n): # base case if (n == 0): return 0 else: # if last bit set add 1 else # add 0 return (n & 1) + countSetBits(n >> 1) # Get value from user n = 13 # Function calling print( countSetBits(n))
Output
3
QUESTIONS) Find Majority Element in an array which appears more than n/2 times.(n is size of array)
Input
{6,4,7,6,6,6,6,9}
Solution:
PYTHON PROGRAM
#include <bits/stdc++.h> using namespace std; void findMajority(int arr[], int n) { int maxCount = 0; int index = -1; // sentinels for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { if (arr[i] == arr[j]) count++; } if (count > maxCount) { maxCount = count; index = i; } } if (maxCount > n / 2) cout << arr[index] << endl; else cout << "No Majority Element" << endl; } int main() { int arr[] = { 6,4,7,6,6,6,6,9}; int n = sizeof(arr) / sizeof(arr[0]); // Function calling findMajority(arr, n); return 0; }
C++ PROGRAM
def findMajority(arr, n): maxCount = 0 index = -1 for i in range(n): count = 1 for j in range(i+1, n): if(arr[i] == arr[j]): count += 1 # update maxCount if count of # current element is greater if(count > maxCount): maxCount = count index = i # if maxCount is greater than n/2 # return the corresponding element if (maxCount > n//2): print(arr[index]) else: print("No Majority Element") # Driver code if __name__ == "__main__": arr = [6,4,7,6,6,6,6,9] n = len(arr) # Function calling findMajority(arr, n)
Output
6
QUESTIONS) Program to validate an IP address
Input
ip1 = "222.111.111.111"
ip2 = "5555..555"
ip3 = "0000.0000.0000.0000"
ip4 = "1.1.1.1"
Solution:
PYTHON PROGRAM
// Program to check if a given // string is valid IPv4 address or not #include <bits/stdc++.h> using namespace std; #define DELIM "." /* function to check whether the string passed is valid or not */ bool valid_part(char* s) { int n = strlen(s); // if length of passed string is // more than 3 then it is not valid if (n > 3) return false; // check if the string only contains digits // if not then return false for (int i = 0; i < n; i++) if ((s[i] >= '0' && s[i] <= '9') == false) return false; string str(s); // if the string is "00" or "001" or // "05" etc then it is not valid if (str.find('0') == 0 && n > 1) return false; stringstream geek(str); int x; geek >> x; // the string is valid if the number // generated is between 0 to 255 return (x >= 0 && x <= 255); } /* return 1 if IP string is valid, else return 0 */ int is_valid_ip(char* ip_str) { // if empty string then return false if (ip_str == NULL) return 0; int i, num, dots = 0; int len = strlen(ip_str); int count = 0; // the number dots in the original // string should be 3 // for it to be valid for (int i = 0; i < len; i++) if (ip_str[i] == '.') count++; if (count != 3) return false; // See following link for strtok() char *ptr = strtok(ip_str, DELIM); if (ptr == NULL) return 0; while (ptr) { /* after parsing string, it must be valid */ if (valid_part(ptr)) { /* parse remaining string */ ptr = strtok(NULL, "."); if (ptr != NULL) ++dots; } else return 0; } if (dots != 3) return 0; return 1; } // Driver code int main() { char ip1[] = "222.111.111.111"; char ip2[] = "5555..555"; char ip3[] = "0000.0000.0000.0000"; char ip4[] = "1.1.1.1"; is_valid_ip(ip1) ? cout<<"Valid\n" : cout<<"Not valid\n"; is_valid_ip(ip2) ? cout<<"Valid\n" : cout<<"Not valid\n"; is_valid_ip(ip3) ? cout<<"Valid\n" : cout<<"Not valid\n"; is_valid_ip(ip4) ? cout<<"Valid\n" : cout<<"Not valid\n"; return 0; }
C++ PROGRAM
# your code goes here def in_range(n): #check if every split is in range 0-255 if n >= 0 and n<=255: return True return False def has_leading_zero(n): # check if every split has leading zero or not. if len(n)>1: if n[0] == "0": return True return False def isValid(s): s = s.split(".") if len(s) != 4: #if number of splitting element is not 4 it is not a valid ip address return 0 for n in s: if has_leading_zero(n): return 0 if len(n) == 0: return 0 try: #if int(n) is not an integer it raises an error n = int(n) if not in_range(n): return 0 except: return 0 return 1 if __name__=="__main__": ip1 = "222.111.111.111" ip2 = "5555..555" ip3 = "0000.0000.0000.0000" ip4 = "1.1.1.1" print(isValid(ip1)) print(isValid(ip2)) print(isValid(ip3)) print(isValid(ip4))
Output
Valid
Not valid
Not valid
Valid
QUESTIONS) Maximum profit by buying and selling a share at most k times
Input
3
[100, 30, 15, 10, 8, 25, 80]
Solution:
PYTHON PROGRAM
#include <climits> #include <iostream> using namespace std; int maxProfit(int price[], int n, int k) { int profit[k + 1][n + 1]; // For day 0, you can't earn money // irrespective of how many times you trade for (int i = 0; i <= k; i++) profit[i][0] = 0; // profit is 0 if we don't do any transaction // (i.e. k =0) for (int j = 0; j <= n; j++) profit[0][j] = 0; // fill the table in bottom-up fashion for (int i = 1; i <= k; i++) { for (int j = 1; j < n; j++) { int max_so_far = INT_MIN; for (int m = 0; m < j; m++) max_so_far = max(max_so_far, price[j] - price[m] + profit[i - 1][m]); profit[i][j] = max(profit[i][j - 1], max_so_far); } } return profit[k][n - 1]; } // Driver code int main() { int k = 3; int price[] ={ 100, 30, 15, 10, 8, 25, 80}; int n = sizeof(price) / sizeof(price[0]); cout << "Maximum profit is: " << maxProfit(price, n, k); return 0; }
C++ PROGRAM
def maxProfit(prices, n, k): # Bottom-up DP approach profit = [[0 for i in range(k + 1)] for j in range(n)] # Profit is zero for the first # day and for zero transactions for i in range(1, n): for j in range(1, k + 1): max_so_far = 0 for l in range(i): max_so_far = max(max_so_far, prices[i] - prices[l] + profit[l][j - 1]) profit[i][j] = max(profit[i - 1][j], max_so_far) return profit[n - 1][k] # Driver code k = 3 prices = [100, 30, 15, 10, 8, 25, 80] n = len(prices) print("Maximum profit is:", maxProfit(prices, n, k))
Output
Maximum profit is: 72
QUESTIONS) Number of subarrays having product less than K
Input
100
[1, 9, 2, 8, 6, 4, 3]
Solution:
PYTHON PROGRAM
#include <iostream> using namespace std; int countsubarray(int array[], int n, int k) { int count = 0; int i, j, mul; for (i = 0; i < n; i++) { // Counter for single element if (array[i] < k) count++; mul = array[i]; for (j = i + 1; j < n; j++) { // Multiple subarray mul = mul * array[j]; if (mul < k) count++; else break; } } return count; } // Driver Code int main() { int array[] = {1, 9, 2, 8, 6, 4, 3}; int k = 100; int size = sizeof(array) / sizeof(array[0]); int count = countsubarray(array, size, k); cout << count << "\n"; }
C++ PROGRAM
def countsubarray(array, n, k): count = 0 for i in range(0, n): # Counter for single element if array[i] < k: count += 1 mul = array[i] for j in range(i + 1, n): # Multiple subarray mul = mul * array[j] if mul < k: count += 1 else: break return count # Driver Code array = [1, 9, 2, 8, 6, 4, 3] k = 100 size = len(array) count = countsubarray(array, size, k) print(count, end=" ")
Output
16
Follow our Dailyrecruitment.in for more upcoming information
JOB ALERT ON INSTAGRAM | FOLLOW NOW>> |
JOB ALERT ON TELEGRAM | JOIN NOW>> |
Govt Jobs by Qualifications
Education & Vacancies | Salary | Apply Link |
---|---|---|
12th Pass Govt Jobs - 18,000+ Vacancies | Rs. 5,200 - 92,300 | Apply Now |
ITI Pass Jobs - 3,500 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
Any Graduate Jobs - 19,100 Vacancies | Rs. 5,200 - 92,300 | Apply Now |
Central Govt Jobs | Rs. 5,200 - 17,000 | Apply Now |
Bank Jobs - 1,000 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Diploma Jobs - 9,300 Vacancies | Rs. 5,200 - 35,000 | Apply Now |
BTech/BE Jobs - 18,000 Vacancies | Rs. 15,000 - 1,00,000 | Apply Now |
Data Entry Jobs - 1,300 Vacancies | Rs. 5,200 - 29,200 | Apply Now |
Private Jobs | Rs. 10,000 - 67,700 | Apply Now |