2nd Round Questions
2nd Round Questions
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>GEEKSORGEEKS
SET---36<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Input: ilikesamsung
Output: Yes
The string can be segmented as "i like samsung" or "i like sam sung".<>
3. Print the following pattern
1
3 2
6 5 4
10 9 8 7
10 9 8 7
6 5 4
3 2
1
4. {{DONE}} Given an array as input, The condition is if the number is repeated you
must add the number and put the next index value to 0. If the number is 0 print it
at the last.
Example: Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8}
Output: 4 2 12 8 0 0 0 0 0 .
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>GEEKSORGEEKS SET---
36<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{{{{DONE}}}}}}
Given a set of numbers like <10, 36, 54,89,12> we want to find sum of weights based
on the following conditions
1. 5 if a perfect square
2. 4 if multiple of 4 and divisible by 6
3. 3 if even number
And sort the numbers based on the weight and print it as follows
w e L C O
M E T O Z
O H O C O
R P O R A
oppp
"{ IIT I O n
And print the start and ending index as
<”luke”, “shaw”>
<”wayne”, “rooney”>
<”rooney”, “ronaldo”>
<”shaw”, “rooney”>
Where the first string is “child”, second string is “Father”. And given “ronaldo”
we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our
output should be 2.
1) Alternate sorting: Given an array of integers, rearrange the array in such a way
that the first element is first maximum and second element is first minimum.
Input : (((ab)
Output : (ab)
3) Form a number system with only 3 and 4. Find the nth number of the number
system.
Eg.) The numbers are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444,
3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444 ….
Input : (ab)(ab+)
Output : Invalid
Input : ((a+b)
Output : Invalid
I don’t remember the 5th question.
. Write a program to give the following output for the given input
Eg 1: Input: a1b10
Output: abbbbbbbbbb
Eg: 2: Input: b3c6d15
Output: bbbccccccddddddddddddddd
The number varies from 1 to 99.
2. Write a program to sort the elements in odd positions in descending order and
elements in ascending order
Eg 1: Input: 12345
Output:
1 5
2 4
3
2 4
1 5
Eg 2: Input: geeksforgeeks
Output:
g s
e k
e e
k e
s g
f r
o
f r
s g
k e
e e
e k
g s
4. Find if a String2 is substring of String1. If it is, return the index of the
first occurrence. else return -1.
Eg 1:Input:
String 1: test123string
String 2: 123
Output: 4
Eg 2: Input:
String 1: testing12
String 2: 1234
Output: -1
5. Given two sorted arrays, merge them such that the elements are not repeated
Eg 1: Input:
Array 1: 2,4,5,6,7,9,10,13
Array 2: 2,3,4,5,6,7,8,9,11,15
Output:
Merged array: 2,3,4,5,6,7,8,9,10,11,13,15
6. Using Recursion reverse the string such as
Input:
N=4 M=5
Output:
X X X X
X 0 0 X
X 0 0 X
X 0 0 X
X X X X
Input:
N=6 M=7
X X X X X X
X 0 0 0 0 X
X 0 X X 0 X
X 0 X X 0 X
X 0 X X 0 X
X 0 0 0 0 X
X X X X X X
Level three:
1) To output the given string for the given input which is an integer.
Input: 1
Output: A
Input: 26
Output: Z
Input : 27
Output: AA
Input: 28:
Output: AB
Input: 1000
Output: ALL
2) Input:
Number of elements in set1: 4
Elements are: 9, 9, 9, 9
Number of elements in set 2: 3
Elements are: 1,1,1
Output:
1, 0, 1, 1, 0
Input:
Number of elements in set1: 11
Elements are: 7,2,3,4,5,3,1,2,7,2,8
Number of elements in set 2: 3
Elements are: 1,2,3
Output: 7,2,3,4,5,3,1,2,8,5,1
Program 1:
Help john to find new friends in social network
Input:
3
Mani 3 ram raj guna
Ram 2 kumar Kishore
Mughil 3 praveen Naveen Ramesh
Output:
Raj guna kumar Kishore praveen Naveen Ramesh
Program 2:
Input:
With the starting and ending time of work given find the minimum no of workers
needed
Program 3:
Find the union intersection of two list and also find except (remove even elements
from list1 and odd elements from list2)
Input
List 1: 1,3,4,5,6,8,9
List 2: 1, 5,8,9,2
Union: 1, 3,4,5,6,8,9,2
Intersection: 1,5,8,9
Except: 1, 3, 5,9,8,2
Program 4:
Output:
4 1 2
7 5 3
8 9 6
Output:
5 1 2 3
9 10 6 4
13 11 7 8
14 15 16 12
Program 5:
Find the largest possible prime number with given no
Input
5
4691
Output:
9461
Round 3:
For one batch of people
Basic programs like pattern printing
1
22
333
4444
And
1
2 4
3 5 7
6 8 10 12
Q2. Given a string of integers find out all the possible words that can made out of
it in continuous order. Eg: 11112
ans: AAAAB
AKAB
AAKB
AAAL etc.
Q3: Find whether a given number is magic number or not. It is something which gives
same digits even after cubing it.
Q5: Given two numbers and an operation either + or – , perform the operation.
Now remove any zeros if present in the two numbers and perform an operation. See if
the result obtained is same or not after removing zero’s in the original result.
2. Sort the array alternately i.e first element should be max value, second min
value, third second max, third second min. Eg: arr[] = {1,2,3,4,5,6,7} O/P:
{7,1,6,2,5,3,4} Note: no extra space and time complexity should be less;
4. Print the numbers which are mismatched from two array. Arr1 = {a b c d e f g h
i}
arr2 ={ a b d e e g g i i}, O/P- cd, de, f, g, h, i.
Question 2: Given a sliding window of size k print the maximum of the numbers under
the sliding window.
Example: Consider a sliding window of size k equals 3. Let the array be
[3,2,7,6,5,1,2,3,4] the output should print 7 as the first output as first window
contains {3,2,7} and second window contains {2,7,6} and so on and the final output
is {7,7,7,6,5,3,4}
Question 3: Given a array with n elements print the number of occurrences of that
number each number in that array. The order of number doesn’t matter. You can
reorder the elements.
Example : [2,1,3,2,2,5,8,9,8]
Output:
2-3
1-1
3-1
5-1
8-2
9-1
Question 4: Enter two strings from command line and check whether any substring
present in first string that follows the pattern of second sting.. They asked to
implement regular expressions for * and backslash without built in functions.
“abcd” “a*cd” answer : yes
“aaaa” “a*” answer : yes
“a*c” “a\*c” answer:yes
“adsd” “ad” answer:no
Question 5: They gave a passage and the output should be printing out the number of
occurrence of each word and the indices it occurs without using string matching
The passage given was “jana Gana Mana” and so on.. and we have to print number of
jana and it’s indices.i.e at which position it occurs.
I have completed first and 5th program. The programs were not of equal weight-age.
4th and 5th were given more weight-age. They gave importance with the way of
approach. Another guy solved the first 4 programs but he is not selected because of
his inefficient code. And I got selected to the next round just because of the
appropriate data structure and logic the applied.
Given two numbers a and b both < 200 we have to find the square numbers which lie
between a and b(inclusive)
for n = 6
1 7 12 16 19 21
2 8 13 17 20
3 9 14 18
4 10 15
5 11
6
6.Given bigger NxN matrix and a smaller MxM matrix print TRUE if the smaller matrix
can be found in the bigger matrix else print FALSE
7.Given two matrices a and b both of size NxN find if matrix a can be transformed
to matrix b by rotating it 90deg , 180deg , 270deg if so print TRUE else print
FALSE
I solved 7 questions .. Those who solved more than 5 were selected for the next
round.
You’re given an array. Print the elements of the array which are greater than its
previous elements in the array.
Input : 2, -3, -4, 5, 9, 7, 8 Output: 2 5 9You should solve this question in
O(n) time.
You’re given an even number n. If n=4, you have to print the following pattern :
44444334
4334
4444
666666
655556
654456
654456
655556
666666
You’re given a number n. If write all the numbers from 1 to n in a paper, we have
to find the number of characters written on the paper.For example if n=13, the
output should be 18 if n = 101, the output should be 195
A number is called as binary-decimal if all the digits in the number should be
either ‘1’ or ‘0’. Any number can be written as a sum of binary-decimals. Our task
is to find the minimum number of binary-decimals to represent a number.Input :
32Output : 10 11 11
Input : 120
Output : 10 110
You’re given a string as an input. You have to reverse the string by keeping the
punctuation and spaces. You have to modify the source string itself with creating
an another string.
Input :A man, in the boat says : I see 1-2-3 in the sky
Input Output
1 A
26 Z
27 AA
676 ZZZ
2) Given a Roman numeral, find its corresponding decimal value.
https://www.geeksforgeeks.org/converting-roman-numerals-decimal-lying-1-3999/
3) Write a program to print all permutations of a given string. Note here you need
to take all combinations as well, say for the input ABC the output should be as
follows:
Input: ABC
Output:
A
B C
AB AC BA BC CA CB
ABC ACB BCA BAC CBA CAB
4) Write a program to rotate an n*n matrix 90,180,270,360 degree.
https://www.geeksforgeeks.org/inplace-rotate-square-matrix-by-90-degrees/ is the
solution for rotating a matrix 90 degree. For rotating the matrix 180,270,360
degree, u need to call the same method 2,3,4 times based on the input.
5) https://www.geeksforgeeks.org/reverse-words-in-a-given-string/
Conditions:
a) You are allowed to add and subtract the consecutive digits (starting from left).
b) You are allowed to do only one operation on a digit.
c) You cannot perform any operation on a resultant digit of the previous operation.
d) Your code should also find if a given number cannot be converted to a mono digit
number.
Input Output
72581 7(2+5)81
77(8-1)
777
3962 cannot create a mono digit number
8 people cleared this round. They didn’t see any optimization in this round.
Simply, completing 4 or more questions will get you through to the next round. The
interviewers helped us to find some rare corner cases too if we miss anything.
Given an array, find the minimum of all the greater numbers for each element in the
array.
Sample:
Array : {2, 3, 7, 1, 8, 5, 11}
Output:
{2>3, 3>5, 7>8, 1>2, 8>11, 5>7, 11>}
2) Find the largest sum contiguous subarray which should not have negative numbers.
We have to print the sum and the corresponding array elements which brought up the
sum.
Sample:
Array : {2, 7, 5, 1, 3, 2, 9, 7}
Output:
Sum : 14
Elements : 3, 2, 9
3) Given a string, we have to reverse the string without changing the position of
punctuations and spaces.
Sample :
a z o l
n x h o
v y i v
o r s e
Dictionary = {van, zoho, love, are, is}
Output:
zoho
love
Is
5) Given a string, change the order of words in the string (last string should come
first).
Should use RECURSION
Given an odd length word which should be printed from the middle of the word.
The output should be in the following pattern.
Example:
Input: PROGRAM
Output:
G
GR
GRA
GRAM
GRAMP
GRAMPR
GRAMPRO
2. It is a program to implement Least Recently Used (LRU) concept. Given a key, if
it is already existed then it should be marked as recently used otherwise a value
should be stored which is given as input and marked as recently used. The capacity
is to store only 10 key, value pairs. If the table is full and given a new key; the
key, value pair which is not recently used should be deleted which gives
feasibility to store the new key, value pair.
3. Given a few pairs of names in the order child, father. The input is a person
name and level number. The output should be the number of children in that
particular level for the person given.
Example:
Input:
[
{Ram, Syam},
{Akil, Syam},
{Nikil, Ram},
{Subhash, Ram},
{Karthik, Akil}
];
Syam 2
Output: 3 (Syam has Ram and Akil in level 1 and in level 2 he have Nikil, Subhash,
Karthik. So the answer is 3).
Input:
Number of digits:12
9 2 8 1 3 5 6 7 3 1 1 6
Number of digits:9
7 8 4 6 2 1 9 9 7
Output :
9 2 8 9 2 0 2 9 5 1 1 3
value
Input
Array = {1 3 4 8 10 } N = 7
output
true
Input: 3 , 4
Output 12
{-2 -3 4 -1 -2 1 5 -3}
output 7 elements [ 4 -1 -2 1 5]
Input :
8 3 4 7 9 N=7
Output
{3 4 } {7}
Write a program to determine whether a given number can be expressed as sum of two
prime numbers or not.
For example 34 can be expressed as sum of two prime numbers but 23 cannot be.
Input : n = 32
Output : 55
23 + 32 = 55 which is a palindrome.
Input : 39
Output : 363
Question 3 : Given a string, reverse only vowels in it; leaving rest of the string
as it is.
Input : abcdef
Output : ebcdaf
Question 4 : Write a program to check if the given words are present in matrix
given below. The words can be left to right, top to bottom and the diagonals (in
top to bottom direction)
zoho_interview
Question 5 : Write a program to form lines using given set of words. The line
formation should follow below rules.
i) Total characters in a single line excluding the space between the words and the
favorite character should not exceed the given number.
iii) Words should not be broken up. Complete words alone should be used in a single
line. A word should be used in one line only.
Example:
Input: X=2, Y=-2
Output: 0.25
2.Find the distance between two gievn points and round it to the nearest number.
Example:
Input: (2,4)(4,10)
Output: 6
3.Count the numbers of characters in the given string treating ‘$’ as escape
sequence. If ‘$’ is preceeded by ”, consider it as normal ‘$’ and not the escape
sequence. If ” occurs, treat it as single ”.
Example:
Input: Hello$World$
Output: 11
4.Given a 2D matrix, find the sum of all the elements.
Example:
Input: [1 2 3]
[4 5 6]
[7 8 9]
Output: 45
Level 2:
Finish one question to get the next type. Total 5 questions. (3 hours – machine
round)
1.Solve the equation (XpowerY/Z!) + (Z/(X!+Z)) with given values of X, Y, Z. X and
Z cannot be negative.
Example:
Input: X=2, Y=3, Z=4
Output: 1
2.Batman, Spiderman and Superman are going to start a business. The total
investment is 1000M$. Anyone can add new investment to their existing investment.
They can transfer investments between themselves. The program should be in OOP
style and should have a menu for user to do all operations. (Something similar to
below example.)
Constraints:
a.Total investment should always be
equal to or lesser than 1000M$.
b.Spiderman's investment should never
exceed Batman's.
c.Investment cannot go into negative.
d.Display investments on each update.
Example:
Input: batman = 300, spiderman = 250,
superman = 100
Output:
batman - 300
spiderman - 250
superman - 100
add 100 into spiderman
sorry, spiderman cant have more
investment than batman add 200
to batman
batman - 500
spiderman - 250
superman - 100
add 500 to superman
sorry, total investment cant
exceed 1000.
Input: 12
Output: min: 3
2) Search a string in a given 2D matrix. And print its possible path.
allowed movements are right left up and down.
Input: 0 1 1 0
1 1 1 0
0 0 1 1
0 0 1 1
Output: 2.
5) There are n items each with a value and weight. A sack is filled with the
weights. In other words there is an array with of length n having the values of the
items arr[0…n-1] and another array with weight arr[0…n-1].
if a sack is to be filled with weight W find the minimum possible value subset.