0% found this document useful (0 votes)
54 views12 pages

Zoho

Uploaded by

feloc25518
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views12 pages

Zoho

Uploaded by

feloc25518
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

ZOHO LONG PROGRAMMING QUESTIONS(Set 2)

1. Given a number system that only uses the digits 3 and 4, the task is to find the Nth
number in this system.
Explanation:
In this number system, the numbers are generated using only the digits 3 and 4. The
sequence of numbers would look like this:
3, 4, 33, 34, 43, 44, 333, 334, 343, 344, ...
Constraints:
1 <= N <= 10^4

Test Case 1:

Input: n = 5
Output: 43
Explanation: The 5th number in the system is 43.

Test Case 2:

Input: n = 10
Output: 334
Explanation: The 10th number in the system is 334.

12. Trapping Rain water

Given n non-negative integers representing an elevation map where the width of


each bar is 1, compute how much water it can trap after raining.
Follow the steps mentioned below to implement the idea:
Traverse the array from start to end:
For every element:
Traverse the array from start to that index and find the maximum height (a) and
Traverse the array from the current index to the end, and find the maximum height
(b).
The amount of water that will be stored in this column is min(a,b) – array[i], add this
value to the total amount of water stored
Print the total amount of water stored.

Constraints:

n == height.length
1 <= n <= 2 * 104
0 <= height[i] <= 105
Testcase 1:

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]


Output: 6
Explanation: The above elevation map (black section) is represented by array
[0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being
trapped.

Testcase 2:

Input: height = [4,2,0,3,2,5]


Output: 9

3. We can scramble a string s to get a string t using the following algorithm:


If the length of the string is 1, stop.
If the length of the string is > 1, do the following:
Split the string into two non-empty substrings at a random index, i.e., if the string is s,
divide it to x and y where s = x + y.
Randomly decide to swap the two substrings or to keep them in the same order. i.e.,
after this step, s may become s = x + y or s = y + x.
Apply step 1 recursively on each of the two substrings x and y.
Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string
of s1, otherwise, return false.

Constraints:
s1.length == s2.length
1 <= s1.length <= 30
s1 and s2 consist of lowercase English letters.

Testcase 1:

Input: s1 = "great", s2 = "rgeat"


Output: true

Explanation: One possible scenario applied on s1 is:


"great" --> "gr/eat" // divide at random index.
"gr/eat" --> "gr/eat" // random decision is not to swap the two substrings and keep
them in order.
"gr/eat" --> "g/r / e/at" // apply the same algorithm recursively on both substrings.
divide at random index each of them.
"g/r / e/at" --> "r/g / e/at" // random decision was to swap the first substring and to
keep the second substring in the same order.
"r/g / e/at" --> "r/g / e/ a/t" // again apply the algorithm recursively, divide "at" to "a/t".
"r/g / e/ a/t" --> "r/g / e/ a/t" // random decision is to keep both substrings in the same
order.
The algorithm stops now, and the result string is "rgeat" which is s2.
As one possible scenario led s1 to be scrambled to s2, we return true.

Testcase 2:

Input: s1 = "abcde", s2 = "caebd"


Output: false

4. Write a C program that takes a word representation of a 3-digit number as input


from the user, converts it into integer form, calculates the sum of its digits, and
performs the following operations:

If the sum of the digits is odd, remove all odd digits from the number.
If the sum of the digits is even, remove all even digits from the number.
Finally, print the modified number in word representation form.

Contraints:
The input should be in string.
It should contain only alphabets.

Testcase 1:

If the input word representation is "three hundred and twenty-five":


Convert it to integer form: 325
Calculate the sum of digits: 3 + 2 + 5 = 10 (even)
Since the sum is even, remove even digits: 35
Convert the result back to word representation: "thirty-five"
Print the result: "thirty-five"

Testcase 2:

If the input word representation is "one hundred and seventy-nine":


Convert it to integer form: 179
Calculate the sum of digits: 1 + 7 + 9 = 17 (odd)
Since the sum is odd, remove odd digits: 0
Convert the result back to word representation: "zero"
Print the result: "zero"

5. Write a C program that takes a sentence as input from the user. The sentence
should contain more than 15 words. For each word in the sentence, the program
should select the character with the maximum ASCII value and determine if it is a
consonent. If the maximum ASCII value character is a consonent, then print the word
along with the consonent character, otherwise ignore the word.

Contraints:
The input should be in string.
It should contain only alphabets.

Testcase 1:

Input:
naruto is a most popular anime. favourite characters are naruto, sasori, itachi,
kakashi, hinata and jiraya.

Output:
is - s
most - t
anime - n
characters - t
are - r
sasori - s
itachi - t
hinata - t
and - n
jiraya - y

Testcase 2:

Input:
akatsuki is the group of rogue shinobies. sasori, deidara, kakuzu, hidan, itachi,
kisame, tobi, zetsu, pain and konan.

Output:
is - s
the - t
shinobies - s
sasori - s
deidara - r
kakuzu - z
hidan - n
itachi - t
kisame - s
tobi - t
zetsu - z
pain - p
and - n
konan - n

6. Alice is texting Bob using her phone. The mapping of digits to letters is shown in
the figure below.

In order to add a letter, Alice has to press the key of the corresponding digit i times,
where i is the position of the letter in the key.

For example, to add the letter 's', Alice has to press '7' four times. Similarly, to add
the letter 'k', Alice has to press '5' twice.
Note that the digits '0' and '1' do not map to any letters, so Alice does not use them.
However, due to an error in transmission, Bob did not receive Alice's text message
but received a string of pressed keys instead.

For example, when Alice sent the message "bob", Bob received the string
"2266622".
Given a string pressedKeys representing the string received by Bob, return the total
number of possible text messages Alice could have sent.

Since the answer may be very large, return it modulo 109 + 7.


Constraints:

1 <= pressedKeys.length <= 105


pressedKeys only consists of digits from '2' - '9'.

Testcase 1:

Input: pressedKeys = "22233"


Output: 8
Explanation:
The possible text messages Alice could have sent are:
"aaadd", "abdd", "badd", "cdd", "aaae", "abe", "bae", and "ce".
Since there are 8 possible messages, we return 8.

Testcase 2:

Input: pressedKeys = "222222222222222222222222222222222222"


Output: 82876089
Explanation:
There are 2082876103 possible text messages Alice could have sent.
Since we need to return the answer modulo 109 + 7, we return 2082876103 % (109
+ 7) = 82876089.

7. Ajay has a flight to catch in an hour. So he has to reach the airport as fast at
possible. He hires a taxi and promises the taxi driver that if he reaches the airport
within k minutes he would pay the taxi driver double the amount.

The city description is as follows –

The taxi is at point 0,0 & airport is at (n-1,m-1) in a 2 – D grid of n rows and m
columns. The grid has some blocked (represented as’#’) and some unblocked
(represented as’.’) cells.

The starting position of the taxi is in the top – left corner of the grid. It is guaranteed
that the starting position & ending positions are not blocked. Each cell of the grid is
connected with its right ,left,top,bottom cells (if those cells exist ). It takes 1 second
for a taxi to move from a cell to its adjacent cell.

If the taxi can reach the bottom-right (airport) corner of the grid within k seconds,
return the string ‘Yes’. Otherwise , return the string ‘No’.

Constraints

1<_rows<_500
0<_maxTime<_10^6

Testcase 1

2 -> size of grid[] rows =2

.. -> grid = [‘..’,’..’]

..
3 -> maxTime = 3

Sample Output

Yes

Explanation

The grid has 2 rows and 2 columns and the time within which the taxi needs to reach
the bottom-right cell in 3 seconds. Starting from the top-left cell, the taxi can either
move to the top-right unblocked

Testcase 2:

rows =3

grid =[‘..##’,’#.##’,’#…’]

maxTime =5

..##

#.##

#…

It will take the taxi 5 seconds to reach the bottom right corner. As long as k>_5,return

‘Yes’.

Returns:

String;the final string; either ‘yes’ or ‘ No

8. You are given a 0-indexed integer array nums, where nums[i] is a digit between 0
and 9 (inclusive).
The triangular sum of nums is the value of the only element present in nums after the
following process terminates:

Let nums comprise of n elements. If n == 1, end the process. Otherwise, create a


new 0-indexed integer array newNums of length n - 1.
For each index i, where 0 <= i < n - 1, assign the value of newNums[i] as (nums[i] +
nums[i+1]) % 10, where % denotes modulo operator.
Replace the array nums with newNums.
Repeat the entire process starting from step 1.
Constraints:

1 <= nums.length <= 1000


0 <= nums[i] <= 9

Testcase 1:

Input: nums = [1,2,3,4,5]


Output: 8
Explanation:
The above diagram depicts the process from which we obtain the triangular sum of
the array.

Testcase 2:

Input: nums = [5]


Output: 5
Explanation:
Since there is only one element in nums, the triangular sum is the value of that
element itself.

9.The problem is to find the number of groups in a given array where the sum of the
elements in each group is divisible by a given number X, and the group size is
limited to a range of X numbers.

Constraints :

The input array should consist of integers.


The length of the input array should not exceed 1000 elements to ensure efficient
processing.
The value of X should be a positive integer.
The group size range should be from 2 to X elements.
The elements of the array and the value of X should be such that the sum of any
group within the range is representable within the bounds of integer data types to
avoid overflow errors.
The algorithm should efficiently find and count all groups that satisfy the conditions
specified within a reasonable time frame.

Testcase 1:
Input:
Array: 3, 9, 7, 4, 6, 8
X: 3
Output:
3, 9
3, 6
9, 6
3, 9, 6
No of groups: 4

EXPALANATION :

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.

If X is 3, then the group should have only 2 elements and 3 elements from the array
whose sum is divisible by 3.

Testcase 2:
Input:
Array: 5, 10, 15, 20, 25, 30
X: 5
Output:
5, 10
5, 15, 25
10, 15
10, 20, 30
15, 20
20, 25
25, 30
Number of groups: 7

Explanation:
The given array is ``, and the value of X is 5.
The program should find all possible groups where the sum of the elements in the
group is divisible by 5, and the group size is limited to a range of 5 numbers.
The output shows the different groups that satisfy the given conditions.
The first group is ``, where the sum is 15, which is divisible by 5.
The second group is ``, where the sum is 45, which is divisible by 5.
The third group is ``, where the sum is 25, which is divisible by 5.
The fourth group is ``, where the sum is 60, which is divisible by 5.
The fifth group is ``, where the sum is 35, which is divisible by 5.
The sixth group is ``, where the sum is 45, which is divisible by 5.
The seventh group is ``, where the sum is 55, which is divisible by 5.
The total number of groups found is 7.

10. Martha is a very bright student. She loves solving high-level puzzles. She has a
list of ‘N’ puzzles. Each puzzle has some difficulty level. There is a rule that one can
only solve a puzzle with difficulty ‘X’ if she has already solved all the puzzles with
difficulty less than ‘X’. She can’t wait to get a puzzle having a difficulty level higher
than the current puzzle.
Your task is to tell Martha how long she has to wait to get a puzzle having a higher
difficulty level than the current puzzle. If there is no puzzle ahead with a higher
difficulty level, just print "0".
For Example :
Let ‘N’ = 5 and ‘PUZZLE’ = [ 30, 40, 80, 50, 70 ]

After solving the first puzzle, the very next puzzle has a difficulty level 40 and 40 >
30.
Then after 40, the very next puzzle has a difficulty level 80 and 80 > 40.
But for 80, there is no puzzle having a difficulty level greater than 80.
For 50, the very next puzzle has a difficulty level 70 and 70 > 50.
Again for 70, there is no puzzle having a difficulty level greater than 70.

So the output will be [1, 1, 0, 1, 0].


Constraints :
1 <= ‘T’ <= 50
1 <= ‘N’ <= 10^4
30 <= ‘PUZZLE[i]’ <= 100
Where, 'PUZZLE[i]' represents the difficulty level of puzzle 'i'.

Testcase 1:

Sample Input 1 :
2
8
31 56 30 33 32 90 60 54
1
50
Sample Output 1 :
14121000
0
Explanation
For Sample Input 1 :
The first test case for 31 next increasing difficulty = 56 (index diff = 1).
For 56 next increasing difficulty = 90 (index diff = 4).
Similarly, check for 30,33, and 32.
For, 90,60, and 54 there are no greater elements.
In the second test case, there is only one puzzle, so the answer will be zero.

Testcase 2:

Sample Input 2 :
2
5
90 80 70 60 50
5
50 60 70 80 90

Sample Output 2 :
00000
11110

You might also like