Programming Problems For Coding Test Round
Programming Problems For Coding Test Round
2. Given a sorted array of positive integers. Rearrange the array elements alternatively i.e first element
should be max value, second should be min value, third should be second max, fourth should be
second min and so on.
Example:
Input:
N = 11
arr[]={10,20,30,40,50,60,70,80,90,100,110}
Output:110 10 100 20 90 30 80 40 70 50 60
Explanation: Max element = 110, min = 10, second max = 100, second min = 20, and so on...
Modified array is : 110 10 100 20 90 30 80 40 70 50 60.
3. Given a list of non negative integers, arrange them in such a manner that they form the largest number
possible. The result is going to be very large, hence return the result in the form of a string.
Input:
N=4
Arr[] = {54, 546, 548, 60}
Output: 6054854654
Explanation: Given numbers are {54, 546,548, 60}, the arrangement 6054854654 gives the largest
value.
6. Given a string S. The task is to print all permutations of a given string in lexicographically sorted
order.
Input: ABC
Output:
ABC ACB BAC BCA CAB CBA
Explanation: Given string ABC has permutations in 6 forms as ABC, ACB, BAC, BCA, CAB and
CBA .
8. Given a string in roman no format (s) your task is to convert it to an integer . Various symbols and
their values are given below.
I1
V5
X 10
L 50
C 100
D 500
M 1000
Input: s = III
Output: 3
9. Given a string without spaces, the task is to remove duplicates from it.
Note: The original order of characters must be kept the same.
Input: S = "gfggcf"
Output: gfc
Explanation: Only keep the first occurrence
10. Given a string S, find length of the longest substring with all distinct characters.
Input: S = "aabcdefdaa"
Output: 6
Explanation: "abcdef" is the longest substring with all distinct characters.
11. Check whether a number exists in the Fibonacci series or not.
12. Given an integer array ‘arr’ of size N the task is to find the count of elements whose value is greater
than all of its prior elements.
For example,
arr[]={7,4,8,2,9}
As 7 is the first element, it will consider in the result. 8 and 9 are also the elements that are greater
than all of its previous elements. Since total of 3elements is present in the array that meets the
condition. Hence the output = 3.
13. A parking lot in a mall has RxC number of parking spaces. Each parking space will either be
empty(0) or full(1). The status (0/1) of a parking space is represented as the element of the matrix.
The task is to find index of the row(R) in the parking lot that has the most of the parking spaces
full(1).
Note :
RxC- Size of the matrix
Elements of the matrix M should be only 0 or 1.
input :
4 -> Value of R(row)
3 -> Value of C(column)
[0 1 0 1 1 0 1 0 1 1 1 1] -> Elements of the array M[R][C]
Output :
4 -> Row 4 has maximum number of 1’s
14. A party has been organized on cruise. The party is organized 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:
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], while input each element is separate 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 ship : 6
2nd hour :
Entry : 0 Exit : 2
No. of guests on ship : 6-2=4
Hour 3:
Entry: 5 Exit: 1
No. of guests on ship : 4+5-1=8
Hour 4:
Entry : 1 Exit : 3
No. of guests on ship : 8+1-3=6
Hour 5:
Entry : 3 Exit: 4
No. of guests on ship: 6+3-4=5
Hence, the maximum number of guests within 5 hours is 8.
15. If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. (This is essentially
the definition of the / and % operators for integers.) Write a program that asks the user how many
eggs she has and then tells the user how many dozen eggs she has and how many extra eggs are left
over.
A gross of eggs is equal to 144 eggs. Extend your program so that it will tell the user how many
gross, how many dozen, and how many left over eggs she has. For example, if the user says that she
has 1342 eggs, then your program would respond with
Your number of eggs is 9 gross, 3 dozen, and 10
since 1342 is equal to 9*144 + 3*12 + 10.
16. Which integer between 1 and 10000 has the largest number of divisors, and how many divisors does it
have? Write a program to find the answers and print out the results. It is possible that several
integers in this range have the same, maximum number of divisors. Your program only has to print out
one of them.
Hint: The basic idea is to go through all the integers, keeping track of the largest number of divisors
that you’ve seen so far. Also, keep track of the integer that had that number of divisors.
18. Write a C function named concat() which takes three strings A, B, and C as arguments. The function
appends C after B and stores in A. Finally it prints the content of A. DO NOT use any string library
function.
19.