# Darwinbox Online Test Questions and Answers 2024 (Freshers/Experience)

## Darwinbox Online Test Questions and Answers 2024 | Darwinbox Online Test Questions | Darwinbox Online Test Questions With Solutions | Darwinbox Online Test Questions For Freshers | Darwinbox Online Test Questions For Experience

Darwinbox Online Test Questions and Answers 2024: From this article, you may obtain the Darwinbox Campus Recruitment Questions/ Darwinbox Online Test Questions. Every Year the organization will conduct the Online Test & Interview Process to select the capable candidates to fill various Roles. As of now, they are going to conduct the online test for multiple roles. Here we have separately proven the Darwinbox Online for both Freshers & Experienced candidates.

So read the entire article to get detailed information about the Darwinbox Online Test Questions/ Darwinbox Online Test Questions & Answers. Before attending any exams, you should prepare well with their frequently asked questions. To qualify for the test you must prepare well with this Darwinbox Online Test Questions and Answers/Darwinbox Online Questions for Freshers. In the below section, you can get the Darwinbox Online Questions

### Darwinbox Online Test Questions and Solutions For Freshers

Question: Wael is well-known for how much he loves the bitwise XOR operation, while kaito is well-known for how much he loves to sum numbers, so their friend Resli decided to make up a problem that would enjoy both of them. Resil wrote down an array A of length N, an integer K and he defined a new function called  Xor- sum as follows

• Xor-sum(x)=(x XOR A[1])+(x XOR A[2])+(x XOR A[3])+…………..+(x XOR A[N])

Can you find the integer x in the range [0,K] with the maximum Xor-sum (x) value?

Print only the value.

Input format

•  The first line contains integer N denoting the number of elements in A.
• The next line contains an integer, k, denoting the maximum value of x.
• Each line i of the N subsequent lines(where 0<=i<=N) contains an integer describing Ai.

Constraints

• 1<=N<=10^5
• 0<=K<=10^9
• 0<=A[i]<=10^9

Sample Input 1

1
0
989898

Sample Output 1

989898

Explanation:

Xor_sum(0)=(0^989898)=989898

Sample Input 2

3
7
1
6
3

Sample Output 2

14

Explanation

Xor_sum(4)=(4^1)+(4^6)+(4^3)=14.

Sample Input 3

4
9
7
4
0
3

Sample Output 3

46

Explanation:

Xor_sum(8)=(8^7)+(8^4) +(8^0)+(8^3)=46.

### EXAMPLE PROGRAMS

C++ PROGRAM

```#include<bits/stdc++.h>
using namespace std;
unordered_map < int, int >L;

int main ()
{

int n, k, m;
cin >> n >> k;
vector < int >v (n);

for (int i = 0; i < n; i++) { cin >> m;
v[i] = m;
int j = 0;
while (m)
{
L[j] += (m & 1);
m >>= 1;
j++;
}
}

int j = 0, K = k, ans = 0, ans2 = 0;
while (K)
{
j++;
K >>= 1;
}

for (int i = j; i > 0; i--)
{
if (L[i - 1] < n - L[i - 1])
ans != 1;
ans <<= 1; } ans >>= 1;
while (ans > k)
{
ans &= 0;
ans <<= 1;
k <<= 1;
}

for (auto i:v)
ans2 += ans ^ i;

cout << ans2;

}```

JAVA PROGRAM

```import java.util.*;
class Main
{
public static void main (String[]args)
{

Scanner sc = new Scanner (System.in);
int n = sc.nextInt ();
int k = sc.nextInt ();
int arr[] = new int[n];

for (int i = 0; i < n; i++)
arr[i] = sc.nextInt ();

int res = 0, max = Integer.MIN_VALUE;

for (int i = 0; i <= k; i++)
{
res = 0;
for (int j = 0; j < n; j++)
res = res + (i ^ arr[j]);
max = Math.max (res, max);
}
System.out.println (max);
}
}```

Questions: Khaled has an array A of N elements. It is guaranteed that N is even. He wants to choose at most N/2 elements from array A. It is not necessary to choose consecutive elements.  Khaled is interested in XOR of all the elements he chooses. Here, XOR denotes the bitwise XOR operation.

For example:

• If A=[2,4,6,8], then khaled can choose the subset [2,4,8] to achieve XOR=(2 XOR 4 XOR 8)=14.

Khaled wants to maximize the XOR of all the elements he chooses. Your task is to help khaled to find the max XOR of a subset that he can achieve by choosing at most N/2 elements?

Input format:

• The first line contains an integer, N, denoting the number of elements in A.
• Each line i of the N subsequent lines(where 0<=i<=N) contains an integer describing Ai.

Constraints

• 1<=N<=120
• 1<=A[i]<=10^6

Sample Input 1

2
1
2
Sample Output 1
2

Explanation:

N=2,  A=[1,2] khaled can choose the subset[2]. The xor of the elements in the subset is 2. And the number of elements in the subset is 1 which is less than N/2.

Sample Input 2
4
1
2
4
7

Sample Output 2

7

Explanation:

N=4,  A=[1,2,4,7] Khaled can choose the subset [7]. The xor of the elements in the subset is 7, and the number of elements in the subset is 1 which is less than N/2.

### EXAMPLE PROGRAMS

C++ PROGRAM

```#include<bits/stdc++.h>
using namespace std;

int main ()
{
int n;
cin >> n;

int arr[n];

for (int i = 0; i < n; i++) cin >> arr[i];

int M = 1 << 20;
int dp[M];
char res[M];

for (int i = 1; i < M; i++)
dp[i] = INT_MAX;

for (int i = 0; i < n; i++)
{
if (arr[i] == 0)
continue;

for (int j = 0; j < M; j++)
res[j] = 0;

for (int k = 0; k < M; k++) { if (res[k] == 1) continue; if (dp[k] > dp[k ^ arr[i]])
dp[k] = dp[k ^ arr[i]] + 1;

else if (dp[k ^ arr[i]] > dp[k])
dp[k ^ arr[i]] = dp[k] + 1;

res[k ^ arr[i]] = 1;

}
}

int j = M - 1, k = n >> 1;

while (dp[j] > k)
j--;

cout << j;

return 0;

}```

PYTHON PROGRAM

```from itertools import combinations

def fun(arr, N):
sub = []
max_xor = max(arr)
for i in range(1, N // 2):
comb = combinations(arr, i + 1)
for i in comb:
sub.append(list(i))
for a in sub:
z = 0
for b in a:
z = z ^ b
if z > max_xor:
max_xor = z
return max_xor

N = int(input("Enter Length : "))
arr = []
for i in range(N):
arr.append(int(input(f"Enter {i+1} Element : ")))
if N < 3:
print("Output :", max(arr))
else:
print("Output :", fun(arr, N))```

### Darwinbox Online Questions & Answers

Question: Airport Authority

Problem Statement -:

In an airport , the Airport  authority decides to charge some minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay \$1.

Function Description:

Complete the weightMachine function in the editor below. It has the following parameter(s):

Parameters:

 Name Type Description N Integer number of luggage T Integer weight of each luggage weights[ ] Integer array threshold weight

Returns: The function must return an INTEGER denoting the required amount to be paid.

Constraints:

• 1 <= N <= 10^5
• 1 <= weights[i] <= 10^5
• 1 <= T <= 10^5

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of luggages.
• Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing weight of ith luggage.
• The next line contains an integer, T, denoting the threshold weight of the boundary wall.

Sample Cases:

• Sample Input 1
4
1
2
3
4
3
• Sample Output 1
5
• Explanation:
Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.

C PROGRAM

```#include <stdio.h>
long int weightMachine(long int N,long int weights[],long int T)
{
long int amount=0,i;
for(i=0;i<N;i++)
{
amount++;
if(weights[i]>T)
{
amount++;
}
}
return amount;
}
int main()
{
long int N,i,T;
scanf("%ld",&N);
long int weights[N];
for(i=0;i<N;i++)
{
scanf("%ld",&weights[i]);
}
scanf("%ld",&T);
printf("%ld",weightMachine(N,weights,T));

return 0;
}```

PYTHON PROGRAM

```def weightMachine(N,weights,T):
amount=0
for i in weights:
amount+=1
if(i>T):
amount+=1
return amount
N=int(input())
weights=[]
for i in range(N):
weights.append(int(input()))
T=int(input())
print(weightMachine(N,weights,T))```

Question: Self Sufficient

Problem Statement: Abhijeet is one of those students who tries to get his own money by part time jobs in various places to fill up the expenses for buying books. He is not placed in one place, so what he does, he tries to allocate how much the book he needs will cost, and then work to earn that much money only. He works and then buys the book respectively. Sometimes he gets more money than he needs so the money is saved for the next book. Sometimes he doesn’t. In that time, if he has stored money from previous books, he can afford it, otherwise he needs money from his parents.

Now His parents go to work and he can’t contact them amid a day. You are his friend, and you have to find how much money minimum he can borrow from his parents so that he can buy all the books.

He can Buy the book in any order.

Function Description:

Complete the function with the following parameters:

 Name Type Description N Integer How many Books he has to buy that day. EarnArray[ ] Integer array Array of his earnings for the ith book CostArray[ ] Integer array Array of the actual cost of the ith book.

Constraints:

• 1 <= N <= 10^3
• 1 <= EarnArray[i] <= 10^3
• 1 <=  CostArray[i] <= 10^3

Input Format:

• First line contains N.
• Second N lines contain The ith earning for the ith book.
• After that N lines contain The cost of the ith book.

Output Format: The minimum money he needs to cover the total expense.

Sample Input 1:

3

[3 4 2] [5 3 4]

Sample Output 1:

3

Explanation:

At first he buys the 2nd book, which costs 3 rupees, so he saves 1 rupee. Then he buys the 1st book, that takes 2 rupees more. So he spends his stored 1 rupee and hence he needs 1 rupee more. Then he buys the last book.

C++ PROGRAM

```#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, ans =0,sum=0;
cin>>n;
vector<int> arr1(n),arr2(n);
for(int i=0;i<n;i++) cin>>arr2[i];
for(int i=0;i<n;i++) cin>>arr1[i];
for(int i=0;i<n;i++) arr2[i]-=arr1[i];

sort(arr2.begin(),arr2.end(),greater<int>());
for(int i=0;i<n;i++)
{
sum+=arr2[i];
if(sum<0)
{ans+=abs(sum);sum=0;}
}
cout<<ans;
}```

PYTHON PROGRAM

```n=int(input())
L1=[0] *n
L2=[0]*n
for i in range(n):
L2[i]=int(input())
for i in range(n):
L1[i]=int(input())

for i in range(n):
L2[i]=L2[i]-L1[i];

L2.sort()
su=0
ans=0
for i in range(n):
su=su+L2[i]
if su<0:
ans = ans + abs(su)
su=0

print(ans)```

Follow Dailyrecruitment.in for more updates regarding aptitude Questions, Coding Questions, Programming Questions, etc.

### 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