Darwinbox Coding Questions & Answers 2024 | Darwinbox Coding Questions Round 1 | Darwinbox Coding Placement Paper | Darwinbox Coding Questions Round 2 | Darwinbox Previous Coding Question Papers
Darwinbox Coding Questions & Answers 2024: Darwinbox will conduct the Coding Test for each hiring Process. Every year, they hire many employees to fill many positions. As of now, they are going to hold the test for the Darwinbox Coding. So, aspirants who are going to attend this hiring process kindly check out the Darwinbox Coding Questions & Answers before attending the process.
Darwinbox Interview Questions & Answers |
Darwinbox Aptitude Test Questions and Answers |
Darwinbox Online Test Questions and Answers |
All the contenders need to be good before the Test. We have provided the sample Darwinbox Round 1 Coding Questions & Answers for your preparation. 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 Darwinbox Previous Coding Questions
Darwinbox Coding Questions Round 1
Question: Order Check
Problem Statement: In an IT company there are n number of Employees, they are asked to stand in ascending order according to their heights.But some employees are not currently standing in their correct position.
Your task is to find how many employees are there who are not standing in their correct positions.
Example
height=[1,2,1,3,3,4,3]
The 4 employees at indices 1,2,5 and 6 are not in the right positions. The correct positions are (1,1,2,3,3,3,4).Return 4.
Function Description
Complete the function countEmployees in the editor below.
count Employee has the following parameter(s):
int height[n]:an array of heights in the order the employees are standing
Returns:
Int : the number of employees not standing in the correct positions
Constraints
- 1<=n<=10^5
- 1<=height[i]<=10^9
Sample case 0
Sample input 0
7 ->height[] size n=7
1
2
1
3
3
4
3
Sample output 0:
4
Explanation
The four employees who are not standing in the correct positions are at indices [1,2,5,6] return 4. The correct positions are [1,1,2,3,3,3,4].
JAVA PROGRAM
import java.util.*; public class Main { public static int countEmployees (int arr[]) { int n = arr.length; int temp[] = new int[n]; for (int i = 0; i < n; i++) temp[i] = arr[i]; Arrays.sort (arr); int count = 0; for (int i = 0; i < n; i++) if (arr[i] != temp[i]) count++; return count; } 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 (); System.out.println (countEmployees (arr)); } }
PYTHON PROGRAM
def countEmployees(n,arr): dup_arr=arr[:] dup_arr.sort() count=0 for i in range(n): if arr[i]!=dup_arr[i]: count+=1 else: pass return count n=int(input()) arr=[ ] for i in range(n): arr.append(int(input())) print(countEmployees(n,arr))
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; int countEmployees(int arr[], int n) { int temp[n]; for (int i = 0; i < n; i++) temp[i] = arr[i]; sort(arr, arr + n); int count = 0; for (int i = 0; i < n; i++) { if (arr[i] != temp[i]) count++; } return count; } int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; cout << countEmployees(arr, n) << endl; return 0; } Question: Maximum Revenue
Problem Statement: Amit is a salesman who wishes to know the maximum revenue received from a given item of the N products each day . Amit has a sales record of N products for M days.Helo amit to find the highest revenue received each day.
Input :
- The first line of the input consists of two space-separated integers- day(M) and item(N) representing the days and the products in the sales record.
- The next M lines consist of N space separated integers representing the sales revenue from each product each day.
Output:
- Print m space-separated integers representing the maximum revenue received each day .
Example Input:
- 3 4
- 101 123 234 344
- 143 282 499 493
- 283 493 202 304
Output:
- 344 499 493
Explanation:
- The maximum revenue received on the first day is 344 , followed by a maximum revenue of 499 on the second day and a maximum revenue of 493 on the third day.
JAVA PROGRAM
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int m=sc.nextInt(); int n=sc.nextInt(); int arr[][]=new int[m][n]; int i,j; for(i=0;i<m;i++){ for (j=0;j<n;j++){ arr[i][j]=sc.nextInt(); } } for (i=0;i<m;i++){ int max = Integer.MIN_VALUE; for(j=0;j<n;j++){ if(arr[i][j]>max){ max = arr[i][j]; } } System.out.println(max); } } }
PYTHON PROGRAM
m = int(input()) n = int(input()) arr = [] for i in range(0, m): ar = [] for j in range(0, n): ar.append(int(input())) arr.append(ar) for i in arr: print(max(i), end=" ")
C++ PROGRAM
#include <bits/stdc++.h> using namespace std; int main(){ int m,n, i,j; cin >> m; cin >> n; int arr [m][n]; for(i = 0;i < m;i++){ for (j=0;j<n;j++){ cin >> arr[i][j]; } } for (i = 0;i < m;i++){ int max = INT_MIN; for(j=0;j<n;j++){ if(arr[i][j]>max){ max = arr[i][j]; } } cout << max << " "; } return 0; }
Question: Iron Magnet
Problem Statement :
We know iron behaves like magnets when all the north and the south sides are placed accordingly in a balanced way while the north comes first and then the south. Now if you are given the distribution of the north and the south poles inside the iron metal piece, you have to say how many swaps is needed to turn it into an iron, if possible, otherwise print -1.
Input Format: A string consisting N and S as north and south poles.
Output Format:
An integer denoting the number of poles will be needed.
Sample Input:
SNNSN
Output:
3
Output Description:
After we balance the iron in the way NSNNSNSS, we will get a piece of metal that will be balanced as a magnet.
JAVA PROGRAM
s = input() ans = 0 if s[0] != "N": ans += 1 s = "N" + s print(ans + abs(s.count("N") - s.count("S")))
PYTHON PROGRAM
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int res = 0, j = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'N') j++; else j--; if (j < 0) { j++; res++; } } res = res + j; System.out.println(res); } }
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; int main() { string s; int ans = 0, k = 0; cin >> s; for (auto i: s) { if (i == 'N') k++; else k--; if (k < 0) { k++; ans++; } } ans += k; cout << ans; }
Darwinbox Coding Questions Round 2
Question: Death Note
Problem Statement : Ryuk, the Shinigami (God of death) had allowed Light Yagami, a school student, to kill as many people as he can by using a death note. But writing the names barely will allow other people to watch them. So he encrypts the names using digits, where a means 1, b means 2 and so on upto z is 26. Now if he gives numbers, there is a communication error because a number string can be decrypted by the death note in various ways and eventually killing them all. If everyone in the world has a unique name, for a given number, how many people can die?
NOTE THAT: There is every possible name in the world with the 26 letters, and capital or small letters is not a problem.
Input format:
A number stream denoting the first name’s encrypted version
Output Format:
Number of people dying by this.
Constraints:
1<=stream length<=10^8
Sample Input: 1267
Sample Output: 3
Output Specification:Two people of the name azg and lfg die.
PYTHON PROGRAM
def solve(s, n): if n == 0 or n == 1: return 1 ans = 0 if s[n - 1] > "0": ans = solve(s, n - 1) if s[n - 2] == "1" or (s[n - 2] == "2" and s[n - 1] < "7"): ans += solve(s, n - 2) return ans s = input() print(solve(s, len(s)))
C++ PROGRAM
#include <bits/stdc++.h> using namespace std; string s; int ans; void func(int i, int n) { if (i == n - 1 || i == n) { ans++; return; } if (s[i] == '1') func(i + 2, n); else if (s[i] == '2' && s[i + 1] < '7') func(i + 2, n); func(i + 1, n); } int main() { ans = 0; cin >> s; func(0, s.length()); cout << ans; }
JAVA PROGRAM
import java.util.*; class Main { static String s; static int ans; public static void func(int i, int n) { if (i == n - 1 || i == n) { ans++; return; } if (s.charAt(i) == '1') func(i + 2, n); else if (s.charAt(i) == '2' && s.charAt(i + 1) < '7') func(i + 2, n); func(i + 1, n); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); s = sc.next(); func(0, s.length()); System.out.println(ans); } }
Questions: Seating Arrangement in Exam Hall
Problem Statement: Semester exams are going on for university students. Examiners noticed that a group of people are trying to cheat. They marked students of that group as ‘1’ and students of another group ( who are not cheating ) as ‘0’
We can reduce cheating by not allowing students from group 1 to sit together, means no two students from group 1 can sit together. Seatings are marked using above conditions. Your task is to give the seating placement of nth possibility Possibility order from 1 to 10 is given below
[1 10 100 101 1000 1001 1010 10000 10001 10010]
Sample input :
3 → number of test cases
4
6
9
Sample output :
101
1001
10001
Explanation :
4th possibility is 101
6th possibility is 1001
9th possibility is 10001
JAVA PROGRAM
import java.util.*; class Main { public static void possibilities(int n) { int c = 0; String b = ""; for (int i = 1; n != c; i++) { String s = Integer.toString(i, 2); if (!s.contains("11")) { c++; b = s; } } System.out.println(b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); int[] a = new int[tc]; for (int i = 0; i < tc; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < tc; i++) { possibilities(a[i]); } } }
PYTHON PROGRAM
t = int(input()) a = [] m = -1 m1 = -1 for i in range(t): m1 = int(input()) a.append(m1) m = max(m, m1) k2 = 2 n = m + 1 k1 = ["0"] * (n) k1[1] = "1" a1 = 1 while k2 < (n): if k1[a1][-1] == "0": k1[k2] = k1[a1] + "0" k2 += 1 if k2 >= (n): break k1[k2] = k1[a1] + "1" k2 += 1 if k2 >= (n): break a1 += 1 elif k1[a1][-1] == "1": k1[k2] = k1[a1] + "0" k2 += 1 if k2 >= (n): break a1 += 1 for i in a: print(k1[i])
C++ PROGRAM
#include<bits/stdc++.h> using namespace std; int main() { int n, m, Max = 0; cin >> n; vector < int > v(n); vector < string > arr; for (int i = 0; i < n; i++) { cin >> v[i]; Max = max(Max, v[i]); } queue < string > q; q.push("1"); int i = 1; arr.push_back("1"); while (!q.empty()) { //cout<<"TEST"<<endl; string a = q.front(); q.pop(); q.push(a + "0"); arr.push_back(a + "0"); i++; if (a[a.length() - 1] == '0') { q.push(a + "1"); arr.push_back(a + "1"); i++; } if (i > Max) break; } for (int i = 0; i < n; i++) { cout << arr[v[i] - 1] << endl; } }
Questions: Minimum Occurrence (R->Medium)
Problem Statement: Given a sting , return the character that appears the minimum number of times in the string. The string will contain only ascii characters, from the ranges (“a”-”z”,”A”-”Z”,0-9), and case matters . If there is a tie in the minimum number of times a character appears in the string return the character that appears first in the string.
Input Format:
Single line with no space denoting the input string.
Output Format:
Single character denoting the least frequent character.
Constraints:
Length of string <=10^6
Sample Input:
cdadcda
Sample Output:
c
Explanation:
C and A both are with minimum frequency. So c is the answer because it comes first with less index.
JAVA PROGRAM
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=sc.next(); char arr[]=str.toCharArray(); int temp[]=new int[256]; for(int i=0;i < arr.length;i++) { temp[arr[i]]++; } int min=Integer.MAX_VALUE; int index=0; for(int i=255;i >= 0;i--) { if(temp[i]==0) continue; min=Math.min(min,temp[i]); } for(int i=0;i < arr.length;i++) { if(min==temp[arr[i]]) { System.out.println(arr[i]); break; } } } }
PYTHON PROGRAM
s=input() ans=[] for i in s: ans.append(s.count(i)) print(s[ans.index(min(ans))])
C++ PROGRAM
#include <bits/stdc++.h> using namespace std; unordered_map < char,int > F; int main() { string s; int m=INT_MAX; cin >> s; for(auto i:s) F[i]++; for(auto i:F) m=min(m,i.second); for(auto i:s) if(F[i]==m) { cout << i; break; } }
Follow Dailyrecruitment.in for more updates regarding Exams, Coding Questions, Aptitude Questions, Interview Questions, & More
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 |