Q1. Given a non-negative integer array Arr having size N.
Each element of the array will carry a different
value. This means no two elements can have the same values.The candidate has to do this with minimal
changes in the original value of the elements, making every element as least as much value as it
originally had.
Find the minimum sum of all elements that can be set the array for:
Example 1: Input
3 -> Value of N, represents size of Arr
2 -> Value of Arr[0]
2-> Value of Arr[1]
4-> Value of Arr[2]
Output 9
Explanation: As two elements have the same value, max value for the one of them needs to be
incremented to 3. He can set the array with 2+3+4=9
Example 2:
Input
2 -> Value of N, represents size of Arr
3 -> Value of Arr[0]
4-> Value of Arr[1]
5-> Value of Arr[2]
Output Wrong Input
Explanation: Here N=2, so we need to provide value of only two elements but we are providing value of
three elements so result is “Wrong Input”
The Input format for the testing First input line: Accept a single positive integer value for N
representing the size of Arr[] Second input line: Accept N number of integer values separated by a new
line, representing the original value assigned to each element.
Output Format for testing: The output must be a non integer only (See the output format example).
Violation of input criteria: System should display message as “Wrong Input”. Additional messages in the
output will result in the failure of the test cases.
Q2. Joseph is learning digital logic subject which will be for his next semester. He usually tries to solve
unit assignment problems before the lecture. Today, he got one tricky question. The problem statement
is “A positive integer has been given as an input. Convert decimal value to binary representation. Toggle
all bits of it after the most significant bit including the most significant bit. Print the positive integer
value after toggling all bits”.
Constraints 1 <=N <=100
Example 1 Input: 10 ---> Integer
Output: 5 → result - Integer
Explanation:
Binary representation of 10 is 1010. After toggling the bits (1010), will get 0101, which represents “5”.
Hence the output will print “5”.
Example 2 Input: 101 ---> Integer Output: Wrong input → result - String
Explanation: Given integer “101” is out of range. Hence the output will print “Wrong input”.
The input format for testing The candidate has to write the code to accept one input(s). 1. First Input -
First line contains an integer
The output format for testing
1. Print integer value based on the number got after toggling all the bits of given input.
2. Print “Wrong input if the string length is out of the range.
3. Additional messages in output will cause the failure of test cases.
Instructions
1. The system doesn’t allow any kind of hard-coded input value.
2. Written program code by the candidate will be verified against all the inputs which are supplied from
the system.
Q3. Given a string S(input) consisting of * and #. The length of the string is variable. The task is to find
the minimum number of * and # required to make it a valid string. The string is considered valid if the
number of * and # are equal. The * and # can be at any position in the string.
Note: The output will be a positive or negative integer based on number of * and # in the input string.
(* > #) : Positive integer (# > *) : Negative integer (#=*): 0
Example 1: Input ###*** → Value of S Output 0 ---> number of * and # are equal
Example 2: Input ###***# → Value of S Output -1 ---> number of # is more than *
Example 3: Input
#*** → Value of S Output 2 ---> number of * is more than #
The input format for testing The candidate has to write the code to accept one inputs separated by a
new line. First input: Accept a string S without any spaces (consisting of only * and #)
The output format for testing The output should be a positive integer number (check in e.g.s 1, 2 and 3).
Additional messages in output will cause the failure of test cases.
Constraints S = {*,#} 0<len(S)<=50
Q 4. Airport security officials have confiscated several items of the passenger at the security checkpoint.
All the items have been dumped into a huge box(array). Each item possessed a certain amount of
risk(0,1,2). Here is the risk severity of the item representing an array[] of N number of integer values.
The risk here is to sort the item based on their level of risk values range from 0 to 2.
Example 1:
Input:
7 ----- Value of N
[1,0,2,0,1,0,2] -> Element of arr[0] to arr[N-1], while input each element is separated by new line
Output:
0 0 0 1 1 2 2 -> Element after sorting based on the risk severity.
Example 2:
Input:
10 ----- Value of N
[2,1,0,2,1,0,0,1,2,0] -> Element of arr[0] to arr[N-1], while input each element is separated by new line
Output:
0 0 0 0 0 1 1 1 2 2 2 -> Element after sorting based on the risk severity.
Constraints
0<N<=100
0<=arr[i]<=2
Q5. A party has been organised on a cruise. The party is organised for a limited time(T). The number of
guests entering (E[i]) and leaving (L[i]) the party at every hour is represented as elements of the array.
The task is to find the maximum number of guests present on the cruise at any given instance within T
hours.
Example 1:
Input:
5 ---> Value of T
[7,0,5,1,3] ---> E[], element of E[0] to E[N-1], where input each element is separated by new line
[1,2,1,3,4] -----> L[],element of L[0] to L[N-1], where input each element is separated by new line
Output:
8 -----> Maximum number of guests on cruise at an instance.
Explanation:
1st hour
Entry: 7, Exit: 1
No. of guests on the ship: 6
2nd hour:
1st hour
Entry: 0, Exit: 2
No. of guests on the ship: 6 -2 = 4
Hour 3:
Entry: 5, Exit: 1
No. of guests on the ship: 4 + 5 -1 = 8
Hour 4:
Entry: 1, Exit: 3
No. of guests on the ship: 8 + 1 - 3 = 6
Hour 5:
Entry: 3, Exit: 4
No. of guests on the ship: 6 + 3 - 4 = 5
Hence, Maximum Number of guests within 5 hours is 8.
Q6. Given an array Arr[] of size T, contains binary digits. Where 0 represents a biker running to the
north. 1 represents a biker running to the south.
The task is to count crossing bikers in such a way that each pair of crossing bikers (N, S), where
0<=N<S<T, is passing when N is running to the north and S is running to the south.
Constraints:
<=N<S<T
Example -1:
Input:
5. -> Number of elements i.e. T 0. -> Value of 1st element 1. -> Value of 2nd element 0. -> Value of 3rd
element 1. -> Value of 4th element 1. -> Value of 5th element
Output:
Explanation:
The 5 pairs are (Arr[0], Arr[1]), (Arr[0], Arr[3]), (Arr[0], Arr[4]), (Arr[2], Arr[3]) and (Arr[2], Arr[4]).
Note that in all pairs first element is 0, second element is 1 and index of first element is smaller than
index of second element.
The Input format for testing:
First input line: Accept a single positive integer value for T representing the size of Arr[]. Second input
line:: Accept N number of integer values (0 or 1) separated by a new line.
Output Format for Testing:
The output must be a non-negative integer number only (See the output format in example). Additional
messages in the output will result in the failure of test cases.
Q7. A supermarket maintains a pricing format for all its products. A value N printed on each product.
When the scanner reads the value N on the item, the product of all the digits in the value N is the price
of the item. The task is to design a software such that given the code of any item N the
product(multiplication) of all the digits of value should be computed(price).
Example 1:
Input:
5244 -->Value of N
Output:
160 -->Price
Explanation:
From the input above:
Product of the digits: 5,1,4,4
5*2*4*4 = 160
Hence Output is 160
Q8. An event management company has come up with a unique idea of printing their event tickets.
Based on the ticket number combination (str1), the visitor is directed towards a particular class of
audience. The task is to create a program/application to fetch the ticket number based on the following
conditions: Any occurrences of digits EF, 56 and G, & should be deleted The characters EF should be in
the same format.
Example 1:
Input:
4523EF58G -> Value of STR1
Output:
452358 -> After removal of characters ‘EF’ and ‘G’
Example 2:
Input:
E12F35G58 -> Value of STR1
Output:
E12F3558 -> After removal of character ‘G’
Explanation:
In the above example, characters E and F are not together. So, they won’t be deleted. The output will be
with only character G removal.
The Input format for testing The candidate has to write the code to accept 1 input(s). First input -
Accept value for str1 which is a string consisting of numbers and uppercase alphabets without any
spaces.
The output format for testing The output should be a string without any spaces (Check the output in
Example 1 and Example 2) Additional messages in output will cause the failure of test cases.
Constraints: Str={(A,Z),(0-9)} No spaces and special characters allowed. Only uppercase alphabets in the
input string