Zoho Round 2 Questions: Sample Input 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

ZOHO ROUND 2 QUESTIONS

1. Given an array of integers perform the operation, the output array should contain maximum value of next
array indices (I.e. Replace the each array element by next greater element in the array). If there is no element next to
a current element, replace the element value with -1. The given array should also contain negative value as well as
duplicate values. Refer sample input and output:

SAMPLE INPUT 1:
1 2 3 4 5

SAMPLE OUTPUT 1:
5 5 5 5 -1

SAMPLE INPUT 2:
16 8 17 16 9 10

SAMPLE OUTPUT 2:
17 17 16 10 10 -1

2. Given an n x n square matrix, find sum of all sub-squares of size k.


where k <= n. Refer sample input and output:
Explanation:
1st sub-square 1 2 4 5; Sum value is 12.
2nd sub-square 2 3 5 6; Sum value is 16.
3rd sub-square 4 5 7 8; Sum value is 24.
4th sub-square 5 6 8 9; Sum value is 28.

SAMPLE INPUT:
n = 3, k = 2

123
456
789
SAMPLE OUTPUT:
12 16
24 28

3. Given an M X M Square matrix, Traverse the matrix in Mirrored Z form and the print the values.
SAMPLE INPUT:
123
456
789
SAMPLE OUTPUT:
MIRRORED Z TRAVERSEL IS : 3 2 1 5 9 8 7
4. Consider an ATM should contain possible denominations notes, you need to perform the operation by
satisfying the following conditions.
The available denominations are Rs.100, Rs.200, Rs.500, Rs.2000
• Customer should enter the withdrawal amount in multiples of 100
• The withdrawal denomination should contain the possible higher denominations and all lower denominations
• Count of lesser denomination notes should be lesser or equal to the count of its highest denomination
Input Format:
First line corresponds to integer n.
Output Format:
Refer to the sample input and output for formatting specifications.

Sample Input and Output 1:


Enter the withdrawal amount in rupees
500
2*200
1*100
Sample Input and Output2:
Enter the withdrawal amount in rupees
2500
4*500
2* 200
1*100

5. MINIMUM NUMBER OF JUMPS


Given a starting position 'k' and two jump sizes 'd1' and 'd2’, our task is to find the minimum number of jumps needed to
reach 'x' if it is possible. Else print -1.
•At any position P, we are allowed to jump to positions:
• P+d1 and P-d1
• P+d2 and P-d2
Input:
Input is consist of a four integer.
Output:
Refer to the sample input and output for formatting specifications.
Sample Input:
k=10
d1=6
d2-8
x=12
Sample Output:
2
1st step 10+d2 = 18
2nd step 18-d1 = 12

1. Reverse words in a sentence without reversing the whole sentence.


Input:
Input consist of one string.
Output:
Refer to the sample input and output for formatting specifications.

Sample Input 1:
Rotate the wheel through 180 degrees
Sample Output 1:
etatoR eht leehw hguorht 081 seerged

Sample Input 2:
ABCD FEGHI
Sample Output 2
DCBA IHGEF

2. How do you check if two strings are a rotation of each other?


Input:
Input consist of two strings.
Output:
Print "Yes" if two strings are a rotation of each other, otherwise print "No".

Sample Input 1:
"Hello from here"
"reHello from he"
Sample Output 1:
Yes

Sample Input 2:
"Hello from here"
"erHello from he"
Sample Output 2:
No

3. Program to convert a given number to words is discussed here. For example, if 1234 is given as input, the
output should be “one thousand two hundred and thirty four”.
Input:
Input consist of an one integer.
Output:
Refer to the sample input and output for formatting specifications.

Sample Input:
9923
Sample Output:
nine thousand nine hundred and twenty three

4. SHORTEST TIME DURATION


Print the shortest duration between the time values given in the input array. The time values are given in the format
(hour:minute:second). The time values in the array are in no particular order.

Example:
Input : {12:34:55,1:12:13,8:12:15}
Output :
4:22:40
Explanation :
12:34:55 - 8:12:15 = 4:22:40
12:34:55 - 1:12:13 = 11:22:42
8:12:15 - 1:12:13 = 7:0:02
smallest is 4:22:40

Input Format:
The first line of the input consists of an integer, N that corresponds to the number of duration's in the input array.
The next N lines of the input corresponds to the duration's in a given array. Assume that the duration are given in
the format: hours:minutes:seconds

Output Format:
Output is to display the shortest time duration (in hours:minutes:seconds) of all values in a given array Refer to the
sample input and output for formatting specifications.

Sample Input 1:
3
12:34:55
1:12-13
8:12:15
Sample Output 1:
4:22:40

5. REMOVE THE COMMON FRAGMENT IN GIVEN STRINGS


Remove a fragment

Write a program to find a fragment that occurs in all strings, where a fragment is 3 consecutive words.
Note: If you are writing this program in JAVA, don't use built-in functions like split(), indexOf(), replace(),
substring(). etc present in String Class. Do not hard code the output.
Example:
Given three strings like:
S1 = "Every morning I want to do exercise regularly"
S2 = "Every morning I want to do meditation without fail"
S3 = "It is important that I want to be happy always"

Then the:
Common fragment = "I want to"

Explanation:
"I want to" is the common fragment (3 continuous words) found in all three sentences.

Input Format:
First line of the input is an integer n, which corresponds to the number of strings.
Second line of the Input consists of n strings line by line

Output Format:
Display the common fragment.
Refer to the sample input and output for formatting specifications.

Sample Input:
3
Every morning I want to do exercise regularly
Every morning I want to do meditation without fail
It is important that I want to be happy always
Sample Output:
I want to

You might also like