Zoho Questions
Zoho Questions
Eg: Input: 3
Output: 0
303
23032
1230321
Input: 5
Output:0
505
45054
3450543
234505432
12345054321
2. Write a program to Generate a random 10 digit no? (No digits should repeat).
a. First digit should be divisible by 1
b. First 2 digits should be divisible by 2
c. First 3 digits should be divisible by 3
d. First 10 digits should be divisible by 10.
3. Write a program to reverse the given string and if a character is not alphanumeric then
it must remain same
Eg: Input: my house is on fire!!
Output: erif no si esuoh ym!!
4. Get a 3-digit or 2-digit no and find reverse the given no and add it with the same no.
Check whether it is a palindrome. If it is a palindrome, terminate the process or else
take the sum as the input and repeat the same process until a palindrome is obtained.
And terminate the program if the palindrome is not obtained in 5 steps.
Eg: Input:27
27+72=99
Output : It is a palindrome
5. Assume ‘n’ taxi’s available and distance between two consecutive point is 15km. A
linear path
A B C D E F is available and time taken to travel between adjacent point is
1hr. Initially all taxi’s are at point A. The customer gives pickup tie, pickup position ,
destination position and tax company gives taxi number allocated , reaching time.
Cost : for 1st 5km : Rs. 500 and for subsequent kms : Rs. 10
Write a program to (a) find travel history of each taxi car (b) If more than one taxi are
available then one who earned less is allotted (c) If no taxi is available then print
rejected.
6. Given an integer n, form a number triangle.
Example : if n = 5,
output:
0
505
45054
3450543
234505432
12345054321
8. Given a 3 or 2 digit number, add it with its reverse and check if the result is
palindrome. If not, add the result with its result and continue this process for 5 times.
9. Given a line of sentence, reverse the sentence. (White spaces and special characters
retain their same place)
Example : John : oh God ! I cannot believe !
Evei : le bto ! N nacIdo Ghonho !
11. Write a program to Check whether the given string of braces and brackets is valid or
not.
Eg : [({})] Valid string Eg:{([)} Not a valid string
12. Write a program to reverse a string without using a new array and string functions.
17. Write a program to identify second largest number from the given un-sorted array
For example:
Input: {17, 45, 23, 89, 100, 4, 45}
Output: 89
18. Get a 3 digit or 2 digit number and add it with the reversed number. Check whether
the sum is palindrome if not add it with the reversed number and check whether it is
palindrome.
Example:
39+93=132
132+231=363 Stop
122+221=343 Stop
173+371=544
544+445=989 Stop
19. Reverse the string by keeping the special characters in the same position.
my name:? isnatara!jan;
najara:?ta nsiema!nym;
20. Input Input
3 5
0
Output Output
303 505
32023 54045
3210123 5430345
543202345
5 4321012345
21. Input: I buy a pen (by traversing only once through the array)
Output: n ipa u ubi
25. In a matrix, if an element ‘0’ is found, make the corresponding row and column as
‘0’. Find the resultant matrix.
26. Print 1 to 100. Instead of nos. divisible by 15 print “fifteen” instead of nos. divisible
by 3 print “three” instead of nos. divisible by 5, print “five”.
27. 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.
28. sort the array odd numbers in ascending and even numbers in descending.
I/p 5 8 11 6 2 1 7
O/p 1 5 7 11 8 6 2
29. 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
30. 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
31. 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
P M
R A
O R
G
O R
R A
P M
34. 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
T I O n
36. 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.
38. create a “Railway reservation system” with the below 4 modules. The modules were:
1. Booking
2. Availability checking
3. Cancellation
4. Prepare chart
39. 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}
40. Remove unbalanced parentheses in a given expression.
Eg.) Input : ((abc)((de))
Output : ((abc)(de))
Input : (((ab)
Output : (ab)
41. You are in a party of N people, where only one person is known to everyone. Such a
person may be present in the party, if yes, (s)he doesn’t know anyone in the party.
Your task is to find the stranger (celebrity) in party.
You will be given a square matrix M[][] where if an element of row i and column j is
set to 1 it means ith person knows jth person. You need to complete the function
getId() which finds the id of the celebrity if present else return -1. The function
getId() takes two arguments, the square matrix M and its size N.
Input:
The first line of input contains an element T denoting the number of test cases. Then
T test cases follow. Each test case consist of 2 lines. The first line of each test case
contains a number denoting the size of the matrix M. Then in the next line are space
separated values of the matrix M.
Output:
For each test case output will be the id of the celebrity if present (0 based index). Else
-1 will be printed.
User Task:
The task is to complete the function getId() which returns the Id of celebrity if
present, else -1.
Constraints:
1 <= T <= 50
2 <= N <= 501
0 <= M[][] <= 1
Example:
Input (To be used only for expected output) :
1
3
010000010
Output :
1
Explanation :
For the above test case the matrix will look like
010
000
010
Here, the celebrity is the person with index 1 ie id 1
42. Given a string, reverse only vowels in it; leaving rest of the string as it is.
Input : abcdef
Output : ebcdaf
43. 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
44. 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
45. 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
49. It’s about anagram.i/p was array of strings .and a word was given to find whether it
has anagram in given array.
Word: ate
50. Size of the array is given were w is wall, g ground, o ball, numbers are bricks.
I/p size 7
Number of bricks 6
Ball:5(life)
wwwwwww
w w
w 1 1 1 w
w 1 1 1 w
w w
w w
w g g o g g w
There are three commands St, lt, rt straight, left, right respectively.
If it is st the ball moves straight .if there any brick(1) along the way it hit it .then brick
disappear.ball back to original position.if there is no brick .it come to initial position.
I/p st
O/p
wwwwwww
w w
w 1 1 1 w
w 1 1 w
w w
w w
w g g o g g w
Ball count:5
I/p lt
O/p
wwwwwww
w w
w 1 1 1 w
w 1 w
w w
w w
w g o g g g w
Ball count:4
(Lt : ball moves diagonally left there is no bricK on the way so it hit the wall reflect
back horizontally there is a brick(3, 2) after hitting it it moves downwards ball
position changed.hence ball count get reduced. On moving downwards is there any
brick that also disappear.)
Same for rt but moves diagonally right.
This is first module. In second module each brick has value for each hit value get
reduced.it disappear only when it become zero.
51. Two strings of equal length will be given. Print all the adjacent pairs which are not
equal.
Input: asdfghij and adsfgijh
Output: sddshiijjh
52. From the input sentence given, find the strings which are not palindrome and print it.
Input: he knows malayalam
Output: he knows
53. Write an application for booking railway ticket reservation system. The application
should have four functionalities.
1. Book
2. Cancel
3. Print booked tickets (details with summary)
4. Print available tickets (details with summary)
Conditions for booking:
There are a total of 63 berths for 63 confirmed tickets, 9 berths for 18 RAC tickets
and 10 tickets in waiting-list. If the waiting-list ticket count goes above 10, print as
‘No tickets available’. The following passenger details should be obtained from the
user.
1. Name
2. Age
3. Gender
4. Berth Preference
The tickets should not be allocated for children below age 5.But, their details should
be stored. Lower berth should be allocated for persons whose age is above 60 and
ladies with children if available. Side-lower berths should be allocated for RAC
passengers.
Conditions for cancelling:
Whenever a ticket is cancelled, a ticket from RAC should be confirmed and a waiting-
list ticket should move to RAC.
Conditions for printing booked tickets:
Print all the tickets that are filled along with the passenger details and at the end, print
the total number of tickets that are filled.
Conditions for printing available tickets:
Print all the tickets that are unoccupied and at the end, print the total number of tickets
that are unoccupied.
Input Output
1 A
26 Z
27 AA
676 ZZZ
55. 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
BC
AB AC BA BC CA CB
ABC ACB BCA BAC CBA CAB
59. 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
60. Given two Strings s1 and s2, remove all the characters from s1 which is present in s2.
Input: s1=”expErIence”, s2=”En”
output: s1=”exprIece”
61. Given an array with repeated numbers, Find the top three repeated numbers.
input: array[]={3, 4, 2, 3, 16, 3, 15, 16, 15, 15, 16, 2, 3}
output: 3, 16, 15
62. A top secret message containing letters from A-Z is being encoded to numbers using
the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
You are an FBI agent. You have to determine the total number of ways that
message can be decoded.
Note: An empty digit sequence is considered to have one decoding. It may be
assumed that the input contains valid digits from 0 to 9 and If there are leading 0’s,
extra trailing 0’s and two or more consecutive 0’s then it is an invalid string.
Example :
Given encoded message "123", it could be decoded as "ABC" (1 2 3) or "LC" (12
3) or "AW"(1 23).
So total ways are 3.
Input:
First line contains the test cases T. 1<=T<=1000
Each test case have two lines
First is length of string N. 1<=N<=40
Second line is string S of digits from '0' to '9' of N length.
Example:
Input:
2
3
123
4
2563
Output:
3
2
63. Given an array A[] of N positive integers which can contain integers from 1 to N
where elements can be repeated or can be absent from the array. Your task is to count
frequency of all elements from 1 to N.
Input:
First line of input contains an integer T denoting the number of test cases. For
each test case, first line contains an integer N denoting the size of array. The
second line contains N space-separated integers A1, A2, ..., AN denoting the
elements of the array.
Output:
For each test case, output N space-separated integers denoting the frequency
of each element from 1 to N.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 106
1 <= A[i] <= 106
Example:
Input:
2
5
23235
4
3333
Output:
02201
0040
Explanation:
Testcase 1: Counting frequencies of each array elements, we have:
1 occurring 0 times.
2 occurring 2 times.
3 occurring 2 times.
4 occurring 0 times.
5 occurring 1 time.
64. 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
65. Check whether all english alphabets are present in the given sentence or not
I/P: abc defGhi JklmnOP QRStuv wxyz
O/P: True
66. Find the strength of the given password string based on the conditions
Four rules were given based on the type and no. of characters in the string.
Weak – only Rule 1 is satisfied or Rule 1 is not satisfied
Medium – Two rules are satisfied
Good – Three rules satisfied
Strong – All Four rules satisfied
I/P: Qw!1 O/P: Weak
I/P: Qwertyuiop O/P: Medium
I/P: QwertY123 O/P: Good
I/P: Qwerty@123 O/P: Strong