# Wipro Milestone 2 Coding Questions & Answers, Check Wipro Coding Questions

## Wipro Milestone 2 Coding Questions & Answers | Wipro Milestone 2 Coding Questions | Wipro Milestone 2 Coding MCQ Coding Questions | Wipro Milestone 2 Coding Interview Questions with Answers

Wipro Milestone 2 Coding Questions & Answers: The Coding test is containing many programming languages. This Coding Test Round is evaluating your programming Skills and Coding Knowledge. The selection process contains many levels of the test. Coding Test is one of the main difficulty parts in every private sector interviews. Every Candidates mainly focused on this Coding Test. In the Private Sector Company of Wipro is hiring eligible employees. Many of the eligible candidates are applied in the Wipro Milestone 2024. The Wipro will conducting the hiring test for each post. The Milestone round is contains many rounds such as Milestone Round 1, Milestone Round 2, Milestone Round 3 and Milestone Round 4. Here we provided the Common Wipro Milestone 2 Questions and Answers/ Wipro Milestone 2 Coding Interview Questions with Answers. Who are interested in the Milestone Hiring, they definitely prepare for the selection process. The hiring process is containing Milestone Round. Wipro will mostly ask the Wipro Milestone 2 Coding Questions in the C, C++, Java, Python Program. Candidates thoroughly prepare for the Languages for Wipro Milestone 2 Round.

By solving the Wipro Milestone 2 Coding Interview Questions and Answers, you will clear the Wipro Milestone Round 2. Candidates must prepare for the Wipro Milestone 2 test. In this page you can get the Wipro Milestone 2 Coding Interview Questions with Solutions, Wipro Milestone round 2 coding questions, Wipro Milestone 2 Coding Question and Answers etc.

### Wipro Milestone 2 Coding Questions With Solutions

Q1: Alex works at a clothing store. There is a large pile of socks that must be paired by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.

For example, there are n=7 socks with colors ar = {1,2,1,2,1,3,2}. There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color. The number of pairs is 2.

Function Description
Complete the sockMerchant function in the editor below. It must return an integer representing the number of matching pairs of socks that are available.
sockMerchant has the following parameter(s):
n: the number of socks in the pile
ar: the colors of each sock

Input Format
The first line contains an integer n, the number of socks represented in ar.
The second line contains n space-separated integers describing the colors ar[i] of the socks in the pile.

Constraints
1 <= n <= 100
1 <= ar[i] <= 100 & 0 <= i < n

Output Format
Return the total number of matching pairs of socks that Alex can sell.

Sample Input
9
10 20 20 10 10 30 50 10 20
Sample Output
3

Explanation
Alex can match 3 pairs of socks i.e 10-10, 10-10, 20-20
while the left out socks are 50, 60, 20

C Program

```#include<stdio.h>
int sockMerchant(int n, int arr[])
{
int freq[101]={0};
int ans = 0,i;
for(i=0;i<n;i++)
freq[arr[i]]++;
for(i = 0; i <= 100; i++)
{
ans = ans+ freq[i]/2;
}
return ans;
}
int main ()
{
int n;
scanf("%d",&n);
int arr[101],i;
for (i = 0; i < n; i++)
{
scanf("%d",&arr[i]);
}

int ans=sockMerchant(n,arr);
printf("%d\n",ans);
return 0;
}

C++ Program
```
```#include<bits/stdc++.h>
using namespace std;
int sockMerchant(int n, int arr[])
{
int freq[101]={0};
int ans = 0;
for(int i=0;i<n;i++)
{
int value=arr[i];
freq[value]++;
}
for(int i = 0; i <= 100; i++)
{
ans = ans+ freq[i]/2;
}
return ans;
}
int main ()
{
int n;
cin >> n;
int arr[n]={0};
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
int res=sockMerchant(n,arr);
cout<<res<<endl;
return 0;
}```
```Java Program
```
```import java.util.*;
class Main
{
public static int sockMerchant(int n, int arr[])
{
int freq[]=new int[101];
for(int i=0;i<n;i++)
{
freq[arr[i]]++;
}
int ans=0;
for(int i=0;i<=100;i++)
ans=ans+freq[i]/2;
return ans;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
int ans=sockMerchant(n,arr);
System.out.println(ans);
}
}

Python Program ```
```def sockMerchant(n, ar):
pairs = 0
set_ar = set(ar)
for i in set_ar:
count = ar.count(i)
pairs+=count//2
return pairs

n = int(input())
ar = list(map(int, input().split()))
print(sockMerchant(n, ar))```

Q2: Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike, he took exactly n steps. For every step he took, he noted if it was an uphill or a downhill step. Gary’s hikes start and end at sea level. We define the following terms:

• A mountain is a non-empty sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.
• A valley is a non-empty sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level.

Given Gary’s sequence of up and down steps during his last hike, find and print the number of valleys he walked through.

Input Format

The first line contains an integer, , denoting the number of steps in Gary’s hike.

The second line contains a single string of characters. Each character belongs to {U, D} (where U indicates a step up and D indicates a step down), and the i(th) cin the string describes Gary’s i(th) step during the hike.

Constraints

• 2 <= N <= 10^6

Output Format

Print a single integer denoting the number of valleys Gary walked through during his hike.

Sample Input

8

UDDDUDUU

Sample Output

1

Explanation

If we represent _ as sea level, a step up as / , and a step down as \ , Gary’s hike can be drawn as:

_/\      _

\    /

\/\/

It’s clear that there is only one valley there, so we print on a new line.

C Program

```#include<stdio.h>
int countingValley(long int steps, char *path)
{
long int i, level = 0, valley = 0;
for(i=0; i<steps; i++)
{
if(path[i] == 'U')
{
level++;
}
else if(path[i] == 'D')
{
if(level == 1)
{
valley++;
}
level--;
}
}
return valley;
}
int main()
{
long int steps;
scanf("%li",&steps);
char path[steps];
int i, result;
for(i=0; i<steps; i++)
{
scanf("%c",&path[i]);
}
result = countingValley(steps, path);
printf("%d",result);
return 0;
}

C++ Program

```
```#include<bits/stdc++.h>
using namespace std;
int countingValley(long int steps, char *path)
{
long int i, level = 0, valley = 0;
for(i=0; i<steps; i++)
{
if(path[i] == 'U')
{
level++;
}
else if(path[i] == 'D')
{
if(level == 1)
{
valley++;
}
level--;
}
}
return valley;
}
int main()
{
long int steps;
cin>>steps;
char path[steps];
int i, result;
for(i=0; i<steps; i++)
{
cin>>path[i];
}
result = countingValley(steps, path);
cout<<result;
return 0;
}

Java Program

```
```import java.util.*;
class Main
{
public static int countingValley(int n, String path)
{
int level=0,valley=0;
for(int i=0;i<n;i++)
{
if(path.charAt(i)=='U')
level++;
else if(path.charAt(i)=='D')
{
if(level==1)
valley++;
level--;
}
}
return valley;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String str=sc.next();
int result=countingValley(n,str);
System.out.println(result);
}
}```
```Python Program
```
```def countingValley(steps, path):
level = valley = 0
for i in path:
if i == 'U':
level += 1
elif i == 'D':
if level == 1:
valley += 1
level -= 1
return valley

steps = int(input())
path = input()
print(countingValley(steps, path))```

Q3: C Program to check if two given matrices are identical

```#include<stdio.h>
#define N 4
// This function returns 1 if A[][] and B[][] are identical
// otherwise returns 0
int areSame (int A[][N], int B[][N])
{
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
if (A[i][j] != B[i][j])
return 0;
return 1;
}
int main ()
{
int A[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
int B[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
if (areSame (A, B))
printf ("Matrices are identical ");
else
printf ("Matrices are not identical");
return 0;
}
C++ Program```
```#include<bits/stdc++.h>
using namespace std;
#define N 4
// This function returns 1 if A[][] and B[][] are identical
// otherwise returns 0
int areSame (int A[][N], int B[][N])
{
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
if (A[i][j] != B[i][j])
return 0;
return 1;
}
int main ()
{
int A[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
int B[N][N] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
if (areSame (A, B))
cout<<"Matrices are identical";
else
cout<<"Matrices are not identical";
return 0;
}```
`Java Program `
```import java.util.*;
class Main
{
static int size=4;
public static boolean areSame(int A[][], int B[][])
{
int i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
if(A[i][j]!=B[i][j])
return false;
}
return true;
}
public static void main(String[] args)
{
int A[][]={{1,1,1,1},{2,2,2,2},{3,3,3,3,},{4,4,4,4}};
int B[][]={{1,1,1,1},{2,2,2,2},{3,3,3,3,},{4,4,4,4}};
if(areSame(A,B))
{
System.out.println("Matrices are identical");
}
else
System.out.println("Matrices are not identical");
}
}

Python Program
```
```a = [[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]
b = [[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]
if a==b:
prin("Metrices are identical")
else:
pint("Metrices are not identical")```

Keep an eye on Dailyrecruitment.in for the most up-to-date information about upcoming exams and results. Find out about official notices, Exam Patterns, Syllabus, Previous Question Papers, Expected Cut Off, Results, Merit List, Study Materials, and much more. Now is the time to bookmark in order to take advantage of even more amazing career opportunities.

` `

### Govt Jobs by Qualifications

Education & Vacancies Salary Apply Link
10th Pass Govt Jobs - 5,000 Vacancies Rs. 5,200 - 63,200 Apply Now
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