100% found this document useful (1 vote)
354 views

2nd Round Questions

zoho 2nd round

Uploaded by

JAYAPRAKASH D
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
354 views

2nd Round Questions

zoho 2nd round

Uploaded by

JAYAPRAKASH D
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Second Round Questions for Zoho

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>GEEKSORGEEKS
SET---36<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

1. Given a text and a wildcard pattern, implement wildcard pattern matching


algorithm that finds if wildcard pattern is matched with text.
The matching should cover the entire text (not partial text).
The wildcard pattern can include the characters ‘?’ and ‘*’
‘?’ – matches any single character
‘*’ – Matches any sequence of characters (including the empty sequence).

2. {{DONE}} Given an input string and a dictionary of words,


find out if the input string can be segmented into a space-separated sequence
of dictionary words. See following examples for more details.
Example : Consider the following dictionary
{ i, like, sam, sung, samsung, mobile, ice, cream, icecream, man, go,
mango}
Input: ilike
Output: Yes
The string can be segmented as "i like".

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

<10,its_weight>,<36,its weight><89,its weight>


Should display the numbers based on increasing order.

3. {{{DONE}}} Save the string “WELCOMETOZOHOCORPORATION” in a two dimensional


array and search for substring like “too” in the two dimensional string both from
left to right and from top to bottom.

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

Start index : <1,2>

End index: <3, 2>

4. {{DONE}} Given a 9×9 sudoku we have to evaluate it for its correctness. We


have to check both the sub matrix correctness and the whole sudoku correctness.

5. Given a two dimensional array of string like

<”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.

Eg.) Input : {1, 2, 3, 4, 5, 6, 7}


Output : {7, 1, 6, 2, 5, 3, 4}
2) Remove unbalanced parentheses in a given expression.

Eg.) Input : ((abc)((de))


Output : ((abc)(de))

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 ….

4) Check whether a given mathematical expression is valid.

Eg.) Input : (a+b)(a*b)


Output : Valid

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: 13,2 4,15,12,10,5


Output: 13,2,12,10,5,15,4
Eg 2: Input: 1,2,3,4,5,6,7,8,9
Output: 9,2,7,4,5,6,3,8,1
3. Write a program to print the following output for the given input. You can
assume the string is of odd length

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

Eg 1: Input: one two three


Output: three two one
Eg 2: Input: I love india
Output: india love I

Print the given pattern:


Input:
N= 3, M=3
Output:
X X X
X 0 X
X X X

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

2) To find the number of groups and output the groups:


Explanation: To find the sum of the elements in the groups and that sum should be
divisible by input X and the groups should be limited to range with X numbers.
If X is 3, then the group should have only 2 elements and 3 elements from the array
whose sum is divisible by 3.
Input:
Array: 3, 9, 7, 4, 6, 8
X: 3
Output:
3, 9
3, 6
9, 6
3, 9, 6
No of groups: 4

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

Start time end time


1230 0130
1200 0100
1600 1700
Output:
2

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:

Rotate the matrix elements


For 3*3 matrix
Input
1 2 3
4 5 6
7 8 9

Output:
4 1 2
7 5 3
8 9 6

For 4*4 matrix


Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

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

. Given dates in day,month, year order sort them.

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.

Q4: something related to rotating an array.

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.

A 3 hour programming round. (offline method)


Once u complete a question , it shall be verified for given sample test cases and 4
or 5 pre verified test cases. To get the next question every test case has to be
solved. The questions were challenging and explanation was good

the various questions were


1. Cyclic number verification
2. Sorting dates
3. write a code to solve given mathematical expression
4. generation of unique number from any random number
5. given a number u need to print all combination of aphabets for that number
Spiral printing.
O/P
4444444
4333334
4322234
4321234
4322234
4333334
4444444

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;

3. Print all the substring of the given string.

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.

5. Print all possible combinations from the given string.

Given two sorted arrays output a merged array without duplicates.


Array1: [1, 2, 3, 6, 9]
Array2: [2, 4, 5, 10]
Merged Array: [1, 2, 3, 4, 5, 6, 9, 10]

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)

eg) i/p a = 20;b = 100;


o/p 25,36,49,64,81,100
2.Alternately sort an unsorted array..

eg) i/p {5,2,8,7,4,3,9}


o/p {9,2,8,3,7,4,5}
3. Given an array and a threshold value find the o/p

eg) i/p {5,8,10,13,6,2};threshold = 3;


o/p count = 17
explanation:
Number parts counts
5 {3,2} 2
8 {3,3,2} 3
10 {3,3,3,1} 4
13 {3,3,3,3,1} 5
6 {3,3} 2
2 {2} 1
4.a. Given two binary numbers add the two numbers in binary form without converting
them to decimal value.

eg) a = 1010 b = 11001


o/p 100011
b.The two numbers were given in base n
eg) a = 123 b = 13 n = 4
o/p 202
5.Write a program to print the below pattern

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

8 In addition to the above question you have to check if matrix a can be


transformed by mirroring vertically or horizontally to matrix b.

I solved 7 questions .. Those who solved more than 5 were selected for the next
round.

Round 3 : TIME : 3hrs


About 50 – 60 were shortlisted .. This round was also a programming round..
Questions were based of matrix transformation.Each question was an extension of the
previous question in some way..There were 5 questions .. I solved only 2 🙁 But got
selected for the next round , I think it was based on my performance on all
previous rounds..

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

If n=6, then the pattern should be like this :

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

1) Given a number, convert it into corresponding alphabet.

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/

6) Write a program to convert a number into a mono-digit number.

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: house no : 123@ cbe


Output: ebc32 1o : nes@ uoh
4) Given a 2D grid of characters, you have to search for all the words in a
dictionary by
moving only along two directions, either right or down. Print the word if it
occurs.

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

Sample: one two three


Output : three two one

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

4. Given an array of positive integers. The output should be the number of


occurrences of each number.
Example:
Input: {2, 3, 2, 6, 1, 6, 2}
Output:
1 – 1
2 – 3
3 – 1
6 – 2

GIven 2 huge numbers as seperate digits, store them in array


and process them and calculate the sum of 2 numbers and store
the result in an array and print the sum.

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

2.Given sorted array check if two numbers sum in it is a given

value
Input
Array = {1 3 4 8 10 } N = 7
output
true

3. Compiuting value of sin (x)


Input x = 30 n = 10
output = 0.5

Hint : The equation sin(x) = x – x^3 / 3! + x^5 / 5! – ….

4. Write function to find multipication of 2 numbers using +


operator You must use minimu possible iterations.

Input: 3 , 4
Output 12

5. Given array find maximum sum of contiguous sub array

{-2 -3 4 -1 -2 1 5 -3}

output 7 elements [ 4 -1 -2 1 5]

6. Given unsorted array find all combination of the element


for a given sum. Order should be maintained.

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.

Question 2 : Take a 2 or 3 digit input number, reverse it and add it to the


original number until the obtained number is a palindrome or 5 iterations are
completed.

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.

ii) Favorite character is case insensitive.

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.

Input : Max char per line = 10


Favorite character = 'o'
Words : Zoho, Eating, Watching, Pogo
Loving, Mango
Output : Watching Zoho
Eating Mango
Loving Pogo.

1.Solve the equation X power Y with given values.

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.

Find the minimum number of times required to represent a number as sum of


squares.

12 = 1^2 + 1^2 + 1^2 + 1^2 + 1^2 + 1^2 +


1^2 + 1^2 + 1^2 + 1^2 + 1^2 + 1^2
12 = 2^2 + 2^2 + 2^2
12 = 3^2 + 1^2 + 1^2

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.

3) In a given pascal triangle find the possible triangles.

4) in a matrix find the number of rectangles filled with 1s.

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.

You might also like