- Prepare
- All Platforms
- Programming
- Aptitude
- Syllabus
- Interview Preparation
- Interview Exp.
- Off Campus
- Prime Video
- Prime Mock

- PrepInsta Prime
- OffCampus
- The Job Company
- Placement Stats
- Prime Video
- Prime Mock

^{0}Notifications Mark All Read

No New notification

- Login
- Get Prime

# Consultadd Coding Questions and Answers

## Sample Consultadd Coding Questions with Solutions

On this page, you will get Sample Consultadd Coding Questions and Answers, which were asked in Online Coding Test and Technical Interviews included in Consultadd Recruitment Process.

Apart from that you will get Faq’s related to Condultadd Recruitment process including Salary Offered, Eligibility Criteria, and Job Profile and many more.

## Sample Consultadd Coding Questions with Solutions - Set 1

**Question 1: Match**

**Problem Statement :**The number of goals achieved by two football teams in matches in a league is given in the form of two lists. For each match of team B. Compute the total number of matches of team A where team A has scored less than or equal to the number of goals scored by team B in that match.

**Example : **team A =[ 1,2,3]

team B =[ 2,4]

Team A has played three matches and has scored team A =[1,2,3] goals in each match respectively. Team B has played two matches and has scored team B = [2,4] goals in each match respectively. For 2 goals scored by team B in its first match, team A has 2 matches with scores 1,2 and 3 hence , the answer is [2,3].

**Function Description :**

Complete the function counts in the editor below.

Counts has the following parameters:

int teamA(n): First array of positive integers

int teamB(m): Second array of positive integers

**Return :**

int(m): an array of m positive integers, one for each teamB[i] representing the total number of elements from teamA[j] satisfying teamA[j]<_ teamB[i] where 0<_j<n and 0<_i< m, in the given order.

**Constraints :**

2<_n, m<_10^5

1<_ teamA[j]<_10^9,where 0<_j<n.

1<_ teamB[i]<_10^9,where 0<_j<m

**Input format for custom Testing :**

Input from stdin will be processed as follows and passed to the functions.

The first line contains an integer n, the number of elements in teamA.

The next n lines each contain an integer describing teamA[j] where 0<_j<n.

The next line contains an integer m, the number of elements in teamB.

The next m lines each contain an integer describing teamB[i]where 0<_i<m.

**Sample input 0 :**

4 -> teamA[] size n = 4

1 -> teamA = [1,4,2,4]

4

2

4

2-> teamB [] size m = 2

3-> teamB = [3,5]

5

**Sample ōutput 0 :**

2

4

**Explanation 0 :**

Given values are n =4, team A = [1,4,2,4], m= 2, and teamB = [3,5].

For teamB[0] = 3, we have 2 elements in teamA(teamA[0] = 1 and teamA[2] = 2) that are <_ teamB[0].

For teamB[1] = 5, we have 4 elements in teamA(teamA[0] = 1, teams[1] =4, teamA[2] = 2, and teamA[3] =4) that are <_teamB[1].

Thus , the function returns the array [2,4] as the answer.

### Prime Course Trailer

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int teamA[] = new int[n]; for (int i = 0; i < n; i++) teamA[i] = sc.nextInt(); int m = sc.nextInt(); int teamB[] = new int[m]; for (int i = 0; i < m; i++) teamB[i] = sc.nextInt(); Arrays.sort(teamA); int count = 0; for (int i = 0; i < m; i++) { count = 0; for (int j = 0; j < n; j++) { if (teamA[j] <= teamB[i]) count++; else break; } System.out.println(count); } } }

ar=list(map(int,input().split())) br=list(map(int,input().split())) ar.sort() ans=[] import bisect for i in br: ans.append(bisect.bisect(ar,i))print(ans)

**Question 2 : Share Holder (R -> Hard)**

**Problem statement :**

Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.**Note that:**

Ratan never goes into loss.

**Example 1 :**

Price=[1,6,2]

Ratan buys it on the first day and sells it on the second.

**Example 2 :**

Price=[9,8,6]

The Price always went down, Ratan never bought it.

**Input Format:**

First line with an integer n, denoting the number days with the value of the stack

Next n days, telling the price of the stock on that very day.

**Output Format:**

Maximum profit done by Ratan in a single line.

Constraints:

Number of days <=10^8

Sample Input for Custom Testing

**STDIN** **———–**

7

1

9

2

11

1

9

2

**Sample Output**

10

**Explanation**

The maximum profit possible is when Ratan buys it in 1 rupees and sells it in 11.

#include <bits/stdc++.h> using namespace std; int solve(vector < int > v) { int n = v.size(); if (n == 0) return 0; int mx = v[0]; for (int i = 1; i < n; i++) mx = max(mx, v[i]); if (mx <= 0) return 0; int mxSum = 0; int cSum = 0; for (int i = 0; i < n; i++) { cSum += v[i]; if (cSum < 0) cSum = 0; mxSum = max(mxSum, cSum); } return mxSum; } int main() { int n; cin >> n; int price[n]; for (int i = 0; i < n; i++) cin >> price[i]; vector < int > diff; for (int i = n - 2; i >= 0; i--) diff.push_back(price[i + 1] - price[i]); int ans = solve(diff); if (ans < 0) cout << 0 << endl; else cout << ans << endl; }

import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int price[] = new int[n]; for (int i = 0; i < n; i++) { price[i] = sc.nextInt(); } Vector < Integer > diff = new Vector < > (); for (int i = n - 2; i >= 0; i--) { diff.add(price[i + 1] - price[i]); } int ans = solve(diff); if (ans < 0) { System.out.println(0); } else { System.out.println(ans); } } private static int solve(Vector < Integer > v) { int n = v.size(); if (n == 0) { return 0; } int mx = v.get(0); for (int i = 1; i < n; i++) { mx = Math.max(mx, v.get(i)); } if (mx <= 0) { return 0; } int mxSum = 0, csum = 0; for (int i = 0; i < n; i++) { csum += v.get(i); if (csum < 0) csum = 0; mxSum = Math.max(csum, mxSum); } return mxSum; } }

def func(diff): n=len(diff) if n==0: return 0 mx=max(diff) if mx <= 0: return 0 mxS=0 cS=0 for i in diff: cS+=i if cS <= 0: cS=0 mxS=max(cS,mxS) return mxS n=int(input()) arr=[] diff=[] ans=[0] for i in range(n): arr.append(int(input())) for i in range(n-1): diff.append(arr[i+1]-arr[i]) ans=func(diff) if ans < 0: print("0") else: print(ans)

**Question 3: Formatting large Products**

Rohan is weak in mathematics.He is giving mathematics Olympiad , but he got stuck in one of the question .Help rohan to solve the question.In Question there are two positive integer A and B. You have to find the product of all integer between A and B which is represented in the form C=D*10^E , where C is the product of numbers , D and E are non-negative integers and the last digit of D is non-zero.

**Function Description **

Complete the function formatProducts in the editor below, formatProduct must return a string that represents C in the above described form.

Function has the following parameters

**A:** an integer

**B:** an integer

**Constraints**

- A will between 1 and 1,000,000 . Inclusive.
- B will be between A and 1,000,000. Inclusive.

**Sample Input 0 **

1

5

**Sample Output 0**

12 * 10^1

**Explanation **

1*2*3*4*5=120 = 12 * 10^1

**Sample Input 1**

3

10

**Sample Output 1**

18144 * 10^2

**Explanation**

3*4*….*10=1814400 =18144 * 10^2

import java.util.*; public class Main { public static String formatProducts (int a, int b) { int result = 1; for (int i = a; i <= b; i++) result = result * i; int temp = result; int power = 0; while ((result % 10) == 0) { power = power + 1; result = result / 10; } return result + " * 10^" + power; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int a = sc.nextInt (); int b = sc.nextInt (); System.out.println (formatProducts (a, b)); } }

def formatProducts(L,H): a=1 for i in range(L,H+1): a=a*i c=0 while(True): if a%10!=0: break else: c+=1 a=a//10 return (str(a)+" * 10^"+str(c)) L=int(input()) H=int(input()) print(formatProducts(L,H))

**Question 04 : Duplicates **

**Problem statement :** The principal has a problem with repetitions. Everytime someone sends the same email twice he becomes angry and starts yelling. His personal assistant filters the mails so that all the unique mails are sent only once, and if there is someone sending the same mail again and again, he deletes them. Write a program which will see the list of roll numbers of the student and find how many emails are to be deleted.

#### Sample Input:

6

1

3

3

4

3

3

#### Sample Output:

3

#include<bits/stdc++.h> using namespace std; map<int,int> m; int main() { int n,a,ans=0; cin>>n; while(n--) { cin>>a; m[a]++; if(m[a]>1) ans++; } cout<<ans; }

import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); TreeSet list=new TreeSet<>(); for(int i=0;i<n;i++) list.add(sc.nextInt()); System.out.println(Math.abs(n-list.size())); } }

def countDuplicate(numbers): c=0 for i in set(numbers): if numbers.count(i)>1: c+=numbers.count(i)-1 return c n=int(input()) numbers=[] for i in range(n): numbers.append(int(input())) print(countDuplicate(numbers))

**Question 5 : Coin Game (R->Medium)**

**Problem Statement :**

Raman was playing a game, he starts with x coins. Now in every step, he wins and loses and he has to get the money or pay the money as needed. He came in contact with a psychic who can see the future and the Psychic predicted the outcomes after each step. Now Raman wants to start the game with the minimum wage where he doesn’t run out of money. Help Raman to find what money he should start with. The only rule to keep playing is not going in a credit situation.

**Input Format:**

First line with n, number of steps in the game

Next n lines, n integers denoting outcomes of every game. Positive means winning and negative means losing that money.

**Output Format:**

One single integer denoting the minimum amount to start with

**Constraints:**

Number of steps<=10^9

-1000<=Money needed in each step<=1000

**Sample Input:**

4

2

-9

15

2

**Sample Output:**

7

**Explanation:**

If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.

#include <iostream> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int sum = 0, ans = 0; for (int i = 0; i < n; i++) { sum += a[i]; if (sum < 1) { sum = -sum; ans += sum; sum = 0; } } cout << ans << endl; }

import java.util.*; public class Main { 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 sum = 0, ans = 0; for (int i = 0; i < n; i++) { sum += arr[i]; if (sum < 1) { sum = -sum; ans += sum + 1; sum = 1; } } System.out.println(ans); } }

n = int(input()) arr = [] for i in range(n): arr.append(int(input())) s, a = 0, 0 for i in arr: s = s + i if s < 1: a = a + (-1 * s) s = 0 print(a)

## Sample Consultadd Coding Questions with Solutions - Set 2

**Question 1: 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

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

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]); } } }

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])

**Question 2: Stepping Numbers**

**Problem Description :**

Stepping Numbers are numbers in which the adjacent digits differ by 1. For example, 123, 545, and 98 are stepping numbers, while 321, 444, and 75 are not. The task is to find all stepping numbers in a given range [n, m].

**For example**- Range: [100, 500]
- Stepping Numbers: 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345
- Explanation: The stepping numbers between 100 and 500 are 101, 121, 123, 210, 212, 232, 234, 321, 323, 343, and 345. These numbers have adjacent digits that differ by 1.

Write code to find out all the stepping numbers in the given range.

**Input Format:** First line contains two numbers N,M

**Output Format:** Print all the stepping numbers present in the range.

**Constraints:** 0 <= N < M <= 1,000,000,000

#include<bits/stdc++.h> using namespace std; void displaySteppingNumbers(int n, int m) { queue q; for (int i = 1; i <= 9; i++) { q.push(i); } while (!q.empty()) { int stepNum = q.front(); q.pop(); if (stepNum >= n && stepNum <= m) { cout << stepNum << " "; } if (stepNum == 0 || stepNum > m) { continue; } int lastDigit = stepNum % 10; int stepNumA = stepNum * 10 + (lastDigit - 1); int stepNumB = stepNum * 10 + (lastDigit + 1); if (lastDigit == 0) { q.push(stepNumB); } else if (lastDigit == 9) { q.push(stepNumA); } else { q.push(stepNumA); q.push(stepNumB); } } } int main() { int n, m; cout << "Enter the range [n, m]: "; cin >> n >> m; cout << "Stepping Numbers between " << n << " and " << m << ": "; displaySteppingNumbers(n, m); return 0; }

import java.util.LinkedList; import java.util.Queue; public class Main { public static void displaySteppingNumbers(int n, int m) { Queue queue = new LinkedList<>(); for (int i = 1; i <= 9; i++) { queue.add(i); } while (!queue.isEmpty()) { int stepNum = queue.poll(); if (stepNum >= n && stepNum <= m) { System.out.print(stepNum + " "); } if (stepNum == 0 || stepNum > m) { continue; } int lastDigit = stepNum % 10; int stepNumA = stepNum * 10 + (lastDigit - 1); int stepNumB = stepNum * 10 + (lastDigit + 1); if (lastDigit == 0) { queue.add(stepNumB); } else if (lastDigit == 9) { queue.add(stepNumA); } else { queue.add(stepNumA); queue.add(stepNumB); } } } public static void main(String[] args) { int n = 0, m = 100; System.out.print("Stepping Numbers between " + n + " and " + m + ": "); displaySteppingNumbers(n, m); } }

def displaySteppingNumbers(n, m): queue = [] for i in range(1, 10): queue.append(i) while queue: stepNum = queue.pop(0) if stepNum >= n and stepNum <= m: print(stepNum, end=' ') if stepNum == 0 or stepNum > m: continue lastDigit = stepNum % 10 stepNumA = stepNum * 10 + (lastDigit - 1) stepNumB = stepNum * 10 + (lastDigit + 1) if lastDigit == 0: queue.append(stepNumB) elif lastDigit == 9: queue.append(stepNumA) else: queue.append(stepNumA) queue.append(stepNumB) n = 0 m = 100 print("Stepping Numbers between", n, "and", m, ": ", end='') displaySteppingNumbers(n, m)

**Question 3: Sort array after converting elements to their squares**

**Problem Description :**

You are given an array of integers in non-decreasing order. Your task is to sort the array after converting each element to its square.

Write a function ‘sortArrayAfterSquaring’ that takes an array of integers as input and returns the sorted array after converting each element to its square.

**For example**- Input: [1, 2, 3, 4, 5]
- Output: [1, 4, 9, 16, 25]
- Explanation:

In this example, the input array is [1, 2, 3, 4, 5]. After squaring each element, we get [1, 4, 9, 16, 25]. The resulting array is then sorted in ascending order, which gives [1, 4, 9, 16, 25]. Finally, the sorted array is printed.

**Input Format: **Given an sorted array containing positive and negative numbers.

**Output Format:** Print the sorted array containing the squares of the numbers.

#include<bits/stdc++.h> void squareSort(std::vector& arr) { // Calculate squares of each element for (int i = 0; i < arr.size(); i++) { arr[i] = arr[i] * arr[i]; } // Sort the array in ascending order std::sort(arr.begin(), arr.end()); } int main() { std::vector arr = {4, 2, 1, 3, 5}; std::cout << "Original Array: "; for (int i = 0; i < arr.size(); i++) { std::cout << arr[i] << " "; } squareSort(arr); std::cout << "\nSorted Array after Squaring: "; for (int i = 0; i < arr.size(); i++) { std::cout << arr[i] << " "; } return 0; }

import java.util.Arrays; public class Main { public static void squareSort(int[] arr) { // Calculate squares of each element for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] * arr[i]; } // Sort the array in ascending order Arrays.sort(arr); } public static void main(String[] args) { int[] arr = {4, 2, 1, 3, 5}; System.out.print("Original Array: "); for (int num : arr) { System.out.print(num + " "); } squareSort(arr); System.out.print("\nSorted Array after Squaring: "); for (int num : arr) { System.out.print(num + " "); } } }

def square_sort(arr): # Calculate squares of each element arr = [num**2 for num in arr] # Sort the list in ascending order arr.sort() return arr arr = [4, 2, 1, 3, 5] print("Original List:", arr) arr_sorted = square_sort(arr) print("Sorted List after Squaring:", arr_sorted)

**Question 4**

**Problem Description**

**Question:- **Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them later whenever he wants to.

He has recently received N boxes of candies each containing Ci candies where Ci represents the total number of candies in the ith box. Krishna wants to store them in a single box. The only constraint is that he can choose any two boxes and store their joint contents in an empty box only. Assume that there are an infinite number of empty boxes available.

At a time he can pick up any two boxes for transferring and if both the boxes contain X and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too eager to collect all of them he has approached you to tell him the minimum time in which all the candies can be collected.

**Input Format:**

- The first line of input is the number of test case T
- Each test case is comprised of two inputs
- The first input of a test case is the number of boxes N
- The second input is N integers delimited by whitespace denoting the number of candies in each box

**Output Format: **Print minimum time required, in seconds, for each of the test cases. Print each output on a new line.

**Constraints:**

- 1 < T < 10
- 1 < N< 10000
- 1 < [Candies in each box] < 100009

S. No. | Input | Output |
---|---|---|

1 | 1 4 1 2 3 4 | 19 |

2 | 1 5 1 2 3 4 5 | 34 |

**Explanation for sample input-output 1:**

4 boxes, each containing 1, 2, 3 and 4 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Hence total time taken is 19 seconds. There could be other combinations also, but overall time does not go below 19 seconds.

**Explanation for sample input-output 2:**

5 boxes, each containing 1, 2, 3, 4 and 5 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Adding 5 + 10 in a new box takes 15 seconds.Hence total time taken is 34 seconds. There could be other combinations also, but overall time does not go below 33 seconds.

#include<bits/stdc++.h> using namespace std; int main() { int i,j; int num_box=0,k=0,sum=0,times=0,tst_case,temp=0; long c[10000],s[10000]; cout<<("Enter the number of test case:"); cin>>tst_case; cout<<("Enter the number of boxes:"); for(int l=0;l<tst_case;l++) { cin>>num_box; } cout<<("Enter the number of candies in each box:"); for(i=0;i<num_box;i++) { cin>>c[i]; } for(i=0;i<num_box;i++) { for(j=i+1;j<num_box;j++) { if(c[i]>c[j]) { temp=c[i]; c[i]=c[j]; c[j]=temp; } } } sum=0; k=0; for(i=0;i<num_box;i++) { sum=sum+c[i]; s[k]=sum; k++; } times=0; cout<<("Minimum time requried:"); for(i=1;i<k;i++) times=times+s[i]; cout<<times; return 0; }

Output 1 4 1 2 3 4 19

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, i, k = 0, sum = 0, s1 = 0, t, temp = 0, j; long c[] = new long[1000009]; long s[] = new long[100009]; t = sc.nextInt(); for (int l = 0; l < t; l++) { n = sc.nextInt(); for (i = 0; i < n; i++) c[i] = sc.nextLong(); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (c[i] > c[j]) { temp = (int) c[i]; c[i] = c[j]; c[j] = temp; } } } sum = 0; k = 0; for (i = 0; i < n; i++) { sum = (int) (sum + c[i]); s[k] = sum; k++; } s1 = 0; for (i = 1; i < k; i++) s1 = (int) (s1 + s[i]); System.out.println(s1); } } }

Output 1 4 1 2 3 4 19

T = int(input()) arr1 = [] for _ in range(T): N = int(input()) arr = list(map(int, input().split())) arr.sort() count = arr[0] for i in range(1, len(arr)): count += arr[i] arr1.append(count) print(sum(arr1))

Output 1 4 1 2 3 4 19

**Question 5:**

**Problem Description**

**Question – : **Juan Marquinho is a geologist and he needs to count rock samples in order to send it to a chemical laboratory. He has a problem: The laboratory only accepts rock samples by a range of its size in ppm (parts per million).

Juan Marquinho receives the rock samples one by one and he classifies the rock samples according to the range of the laboratory. This process is very hard because the number of rock samples may be in millions.

Juan Marquinho needs your help, your task is to develop a program to get the number of rocks in each of the ranges accepted by the laboratory.

**Input Format: **An positive integer S (the number of rock samples) separated by a blank space, and a positive integer R (the number of ranges of the laboratory); A list of the sizes of S samples (in ppm), as positive integers separated by space R lines where the ith line containing two positive integers, space separated, indicating the minimum size and maximum size respectively of the ith range.

**Output Format: **R lines where the ith line contains a single non-negative integer indicating the number of the samples which lie in the ith range.

**Constraints: **

- 10 <= S <= 10000
- 1 <= R <= 1000000
- 1<=size of Sample <= 1000

**Example 1**

- Input: 10 2
- 345 604 321 433 704 470 808 718 517 811
- 300 350
- 400 700

**Output**: 2 4

**Explanation:**

There are 10 samples (S) and 2 ranges ( R ). The samples are 345, 604,811. The ranges are 300-350 and 400-700. There are 2 samples in the first range (345 and 321) and 4 samples in the second range (604, 433, 470, 517). Hence the two lines of the output are 2 and 4

**Example 2**

- Input: 20 3
- 921 107 270 631 926 543 589 520 595 93 873 424 759 537 458 614 725 842 575 195
- 1 100
- 50 600
- 1 1000

**Output**: 1 12 20

**Explanation:**

There are 20 samples and 3 ranges. The samples are 921, 107 195. The ranges are 1-100, 50-600 and 1-1000. Note that the ranges are overlapping. The number of samples in each of the three ranges are 1, 12 and 20 respectively. Hence the three lines of the output are 1, 12 and 20.

#include<bits/stdc++.h> using namespace std; int main() { int a[1000],s,i,j,t,l1,l2,c=0; cout<<("Enter the number of elements : "); cin>>s; cout<<("Enter the number of ranges : "); cin>>t; cout<<("Enter the elements : "); for(i=0;i<s;i++) cin>>a[i]; cout<<("Enter the range : "); for(i=0;i<t;i++) { cin>>l1>>l2; for(j=0;j<s;j++) { if((a[j]>=l1)&&(a[j]<=l2)) c++; } cout<<("The desired output %d ",c); c=0; } return 0; }

Output Enter the number of elements : 10 Enter the number of ranges : 2 Enter the elements : 345 604 321 433 704 470 808 718 517 811 Enter the ranges : 300 350 400 700 The desired Output : 2 4

import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] a = new int[1000]; int s,i,j,t,l1=0,l2=0,c=0; System.out.println("Enter the no of sample"); s = sc.nextInt(); System.out.println("Enter the no of range"); t = sc.nextInt(); System.out.println("Enter the numbers"); for (i = 0; i < s; i++) { a[i] = sc.nextInt(); } for (i = 0; i< t; i++) { System.out.println("Enter the max and min range"); l1 = sc.nextInt(); l2 = sc.nextInt(); for (j = 0; j < s; j++) { if((a[j]>=l1)&&(a[j]<=l2)) c++; } System.out.println(c); c=0; } } }

samples, ranges =[int(i) for i in input().split()] count = 0 final = [] arr = list(map(int, input().split())) for i in range(0, ranges): range1, range2 = [int(i) for i in input().split()] for j in range(0, samples): if range1 <= arr[j] <= range2: count = count + 1 final.append(count) count = 0 for i in range(0, len(final)): print(final[i], end=" ")

Output 10 2 345 604 321 433 704 470 808 718 517 811 300 350 400 700 2 4

## FAQs related to Consultadd Coding Questions

##### Question 1: How many rounds are there in Consultadd Recruitment Process?

Consultadd has set different Hiring Process for Hiring Software Engineers and Management Trainee Engineers:

**i.e. **For **Software Engineer:**

- Coding Round: 1
- Personal Interview: 3 Technical Rounds

For **Management Trainee Engineer:**

- Group Discussion: 1
- Personal Interview: 2 Rounds

##### Question 2: Does Consultadd asks coding questions in Recruitment Process?

Yes, Coding Questions are included in Online Coding Test and Technical Interview of Consultadd.

##### Question 3: What is the eligibility criteria for the Job roles offered are at Consultadd India?

Consultadd has set different different Eligibility Criteria for Hiring freshers for Different Job Profiles like:

- For
**Software Engineer Level 1:**B.Tech from CS/IT with Score of 65% throughout academics, Batch – 2024 are allowed. - For
**Management Trainee Engineer:**B.Tech from any Branch except CS/IT with Score of 65% throughout academics, Batch – 2024 are allowed.

##### Question 4: What is the salary offered by Consultadd India?

Salary offerd by Consultadd for:

**Software Engineer Level 1 =**₹ 8 – 12 LPA.**Management Tainee Engineer =**₹ 5 LPA.

**Get over 200+ course One Subscription**

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Login/Signup to comment