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

Zohocorp Round 2 Questions - Sample

Question 1:
Finding the minimum duration between the given array of time

Question 2:
Determine if there is a subset of a given array with sum equal to given sum.

Question 3:
Print n*m array in given format.

Question 4:
Generate look and say series for nth term

Question 5:
String reverse

Question 6:
Zigzag traversal in 2 d matrix

Question 7:
Dialing pad codes

Question 8:
Spiral traversal in 2 d matrix

Question 9:
Pendulum sort

Question 10:

To print the common substring of the given three string. Eg:.

Input:

String1: i am Praveen

String2: i am from Tiruppur

String3: i am pursuing ECE


Output : i am

Question 11:

To print the given number in words Eg:.

Input:. 12500

Output:. twelve thousand five hundred

Question 12:

String rotation Eg:.

Input:.

String1: hello from here

String2:. rehello from he

Output: Yes

Question 13:

Shortest time duration Eg:.

Input:. [12:34:55,1:12:13,8:12:15]

Output:. 4:22:40

Explanation:.

12:34:55 - 8:13: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
Question 14:

To compute the given string Eg:.

Input:. babca

Output: 9

Explanation:. The value of the string is 2*2 + 2*1+ 1*3 = 9

Question 15:

Write a program to represent a number(positive integer) as the sum of one


or more distinct Fibonacci numbers in such a way that the sum does not
include any two consecutive Fibonacci numbers.

Example:

Input: 64

Output: 55+8+1

Question 16:

Given a String with numbers and operators. Perform the operation on the
numbers in their respective order. Operator precedence need not be
considered.

The input string will have the numbers followed by the operators.

Example:

Input: "12345 * + - + "

Result: 6 [Explanation: 1 * 2 + 3 - 4 + 5 = 6]

Input: "374291 - - * + -"


Result: -8 [Explanation: 3 - 7 - 4 * 2 + 9 - 1 = -8]

Question 17:

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 and repeat the same sorting for the subsequent pairs

first element-first maximum

second element-first minimum

third element-second maximum

fourth element second minimum

Example:

Input (5,7,3,1,4,6,2)

Output (7,1, 6,2,5, 3, 4)

Question 18:

Assume a two dimensional string array. Each array contains child and father
details. O'th element is the child and '1'st is the parent. Write a program to
accept a name and find the number of children and grand children he has.
Don't use any brute force methods.Assume names are unique.

Example:

Data:

[Surya, Sivakumar],

[Karthi, Sivakumar],

[Sivakumar, Rakkaiya).

[Dev, Surya),
[Umayaal, Karthi],

[Diya, Surya],

[Prabu, Sivaji],

[Vikram, Prabu]

Examples:

Input: Surya, 1

Output: 2

Input: Karthi, 1

Output: 1

Input: Sivakumar, 2

Output 3

Question 19:

Given a positive integer N, the task is to find the nearest Fibonacci number
to the given integer N. If there are two Fibonacci Numbers having same
difference from N, then print the smaller value.

Question 20:

Maximum Product Subarray GFG

Question 21:

Ensuring the correctness of Stack Operations GFG

Question 22:
Length of Longest Substring without repeating characters GFG

Question 23:

Minimum distance between the given words

i/p: given string: Hi there, how you have been?

word1: there

word2: been

o/p: 3 (in between , 'there' and 'been' there are minimum 3 words)

Question 24:

Maximum profit by buying and selling a share at most twice GF

Question 25:

Find the length of longest substring without repeating characters.

Question 26:

Best time to buy stock (Array based problem)

Question 27:

Maximum Product Subarray

https://leetcode.com/problems/maximum-product-subarray/

Question 28:

Validate Stack Sequences (refer in leetcode)

Question 29:

Given an integer array, find the contiguous non empty subarray

within the array that has largest product, and return the product

Question 30:
Given a list of distinct integer pushes and another list of integer

pops, return whether this a valid sequence of stack push and pop

actions

Question 31:

Find the repeating elements in array, return it in assorted order.

Question 32:

Find the length of the longest consecutive elements sequence for an


unsorted array.

Question 33:

Each element in an array will have the rank. You have to sort the elements
of the array based on rank. If two elements have the same rank then the
element must be sorted based on their numeric values.

Array: [1,5,6,3,10]

Rank: [100,0,1,100,2]

Op: [5,6,10,1,3]

Question 34:

Finding distinct element common to all rows of matrix.

Question 35:

Pattern printing

121

12321

1234321

123454321
Question 36:

Buy And Sell Stocks with utmost two transactions

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii

Question 37:Check if the given push and pop sequences of Stack is valid or
not.

https://www.geeksforgeeks.org/check-if-the-given-push-and-pop-
sequences-of-stack-is-valid-or-not/

Question 38:

Ques based on Sliding Window Maximum Technique.

Question 39:

To find the length of the longest beautiful substring . A string is considered if


each vowel appear at least once and the letters must be arranged in
alphabetic order . For example, “aeiou” is beautiful where as “eioau” is not
beautiful.

Sample input: aeiaaioaaaaeiiiiouuuooaauuaeiu

Output:13

Question 40:To find the length of the maximum size turbulent sub array. A
sub array is turbulent if the comparison signs changes for every adjacent
pairs of the elements in a subarray.

Sample input: 9 4 2 8 6 7 7 2 10

Output:5

Question 41:
To find the maximum profit from the array of prices given for the nth day.
You may complete atmost 2 transactions .

Sample Input:3 3 5 0 0 3 1 4

Output:6

Question 42:Given an N jobs with start time and end time and CPU
load .Print the maximum CPU load for a particular time.

Input:4(no of jobs)

035

248

598

156

Output: 19

Question 43:

Given an array, find the sum of all the numbers in array

except the one odd number after an even number.

Eg : Input : 4 8 2 5 5 6

Output : 25

Question 44:

Given an array, find the element of the array which is

closest to the average of all elements of the array.

Eg : 1. Input : 1 2 3 4 5

Output : 3

2. Input : 18 15 25 14 10

Output : 15
Question 45:

A person is under going intermittent fasting. He/She

can take only 2 meals per day. The second meal should

be taken within 8 hours and 3 hours after the first meal.

And the next meal should be taken after 16 hours.

Given an array which denotes the number of hours in

the range of 1 to 50. The hours in which the person

taken the meal is given in the array. Verify whether the

person have followed the Intermittent fasting with its

constraints.

Eg : Input : 0 4 21 26 44

Output : yes

Input : 0 17 21 39 44 62

Output : yes

Input : 0 4 20 26 44

Output : no

Question 46:

Given three integers, find whether the numbers are

trap or not.

Trap conditions:

• If the two numbers which is given to the trap is

equal, then it is a trap. (i.e : x=3, y=3 => x=y, so it

is a trap).
• In the given two numbers, if any one of the number

is factor of another number, then it is trap. (i.e : x=

3, y=12 => x%y=0, so it is a trap).

• If the given two numbers does not fall under the

above constraints, then the sum of digits of x have

to be calculated( i.e : stored in z variable) and trap

function have to be called with z and y( i.e : y

remains unchanged)

Eg : 1).x= 895 y=12

z= 22 y=12 => it is a trap.

2). x=895 y=11

z=22 y=11 => it is a trap.

Given three numbers a, b and y.

Step.1: Generate numbers in the range a to b.

Step.2 : Check every number in the range a to b

with y whether it is trap or not.

Step.3 : If the two numbers are trap increment the y

as y+2. Else decrement the y by 1.

Step.4 : If y value is less than 3, reset the y value to 3.

Eg : Input : 2 10 12

Output : yes

Question 47:

Merge two arrays


Question 48:

Given an array, move all the zeroes to the end of the array

Question 49:

Write a program to find the position of the seat in the flight if the seat
number is given.

If it is a window seat, print “WS”, if it is a middle seat, print “MS”, if it is a


corner seat,

print “CS”.

FLIGHT SEAT ARRANGEMENT

INPUT 1

22

OUTPUT

CS

INPUT 2

41

OUTPUT

MS

INPUT 1

WS MS CS CS MS WS

123

12 11 10

13 14 15

24 23 22

25 26 27
36 35 34

37 38 39

48 47 46

456

987

16 17 18

21 20 19

28 29 30

33 32 31

40 41 42

45 44 43

OUTPUT:

WS

Question 50:Given an array, tell if there exists an element in the array such
that the sum of the elements to its left side is equal to the sum of the
elements to its right side

Question 51:Given an array of numbers find the sum of the array by


rejecting an odd number which is consecutive of an even number.

Input: 4 2 4 3 5

Output: 15

Explanation: 4+2+4+5= 15(rejecting 3 as it is the consecutive number)

Question 52: Given an array of numbers find the average of the numbers in
the list and return the average

number or the number closest to the average in the array.

Input: 1 2 3 4 5
Output: 3

Explanation: average of array is 3 and number 3 is there in the list so return


it.

Input: -12 4 2 7 8 9

Output: 2(or 4)

Explanation: average of array is 3, (the number is not there so the closest


value is either 2 or 4).

Question 53:

Fasting sequence problem:

Given an array of number, find whether the number follows the given
sequence or not.

M(3> x <8),M(x>16 ), M(3> x <8),M(x>16 ), M(3> x <8),M(x>16 ),


……….

(or)

M(x>16 ), M(3> x <8),M(x>16 ), M(3> x <8),M(x>16 ), M(3> x <8),


……….

If the array follows the sequence return “Yes” else “No”

Input: 0 3 21 26 39

Output : No

Explanation: The difference between 0 and 3 is not between (M(3> x <8)),


sequence failed

Input: 0 4 21 26 39

Output : No

Explanation: The sequence is followed.


Question 54:Traps problem:

Given three variables N1,N2 and y.

A number x between the range N1,N2 is said to be Trap if it follows the


below condition:

1. if x==y

2. if x is a multiple of y.

If the number is not trap , then find the sum of digits and try it with above
condition.

Ex: 895,11 is not trap.

8+9+5=22 ,11 is a trap.

If the number in the range is trap increment y by 2 , if not trap after sum of
digit also then decrement

the y by 1.

If y is less that 3 , then reset to 3.

Output is to print the trap numbers from the range N1 and N2.

Q5. Given an n*n matrix , traverse the matrix in a particular order from 0,0
to n,n and return to 0,0. The

output is the total numbers of 1’s in the path.

The matrix consists only 0 – there is a path.

1 – count along with the path

-1 – block.

For 0,0 to n,n – only right and down move.

For n,n to 0,0 – only left and up move.


Question 55:

Remove Duplicate letters Leet316

Question 56:

Merging elements of two different arrays alternatively in third array GFG

Question 57:

Pascal’s Triangle Leet118

Question 58:

Printing the sum of arrays excluding the odd numbers following the even
number.

Question 59:

Sum of the elements in the array.If any odd number occurs after an even
number skip that element alone.

Testcase1:

Input:1 2 3 4 6

Output:13(skips element 3 as it occurs after 2 which is even)

Testcase2:

Input:5 3 2 4 6 7 1

Output:21(skips element 7 alone as it occurs after 6)

Question 60:

Given two arrays print the first element of first array as first and then the
first element of second array and so on.

Input - 20 30 40 50

1 2 3 4
Output – 20 1 30 2 40 3 50 4

Question 61:

Fasting rule

i. A person should eat two meals between 8 hours and there should be
more than 3 hours difference between two meal times.

ii. After that two meals ,the person should not eat anything for the next
16 hours.

Check if a person follows the Fasting rule.

A) Input : 2 7 27 32 48

Output : YES

B) Input : 2 3 19 24 41 45

Output : NO

Question 62:

Given two arrays A and B containing N integers, find a number from A and
another number from B such that their sum is minimum and their index
positions are not same.

INPUT:

54321

52145

Output:

Question 63:
Reversing K continuous numbers from a list, if the number of

elements is less than K reverse remaining elements.

Ex:

Array = [1,2,3,4,5,6,7,8]

K=3

Output [3,21,6,5,4,8,7]

Array = [1,2,3,4,5,1]

K=5

Output [5,4,3,2,1,1]

Question 64:

Create a new sorted array[ascending] by merging two sorted arrays

[ascending or descending order] without duplicate elements. Only one

loop should be used to merge, remove duplicate and sort.

Ex: [5,3,1] [2,4,5]

Output:

[1,2,3,4,5]

Ex: [9,9,1] [1,2,9]

Output:

[1,2,9]

Question 65:

Find the longest subarray with equal number of one’s and zero’s

from an array.

Ex: [1,0,1,1,1,0,0,1]
Output:

1 to 6

Ex: [0,1,0,1,0,1,0,1]

Output:

0 to 4

Move Zeros to Right

Question 66:Give the character with it occurrence in a string

Input : occurrence

Output : o1c3u1r2e1n1

Question 67: Group Anagram

https://leetcode.com/problems/group-anagrams/description/

Question 68:Climbing stairs

https://leetcode.com/problems/climbing-stairs/description

Question 69:Given a number N, print the following pattern. Examples :

Input : 4

Output :

4444444

4333334

4322234

4321234

4322234

4333334
4444444

Question 70:Given an array of integers and a size k, Reverse every sub-


array of k group elements in the same array.Don't create another array for
this.

Example1 :

Input: {1, 5, 7, 2, 3, 6, 7, 8, 9}, k = 3

Output: {7, 5, 1, 6, 3, 2, 9, 8, 7}

Example2 :

Input: {1, 2, 3, 4, 5, 6, 7, 8}, k = 5

Output: {5, 4, 3, 2, 1, 8, 7, 6}

Question 71:

Print the largest sequence of consonant sub-array between two

vowels

Example:

input: "alphabet"

output: "pha"

input: "hhhhhhappa"

output: "pp"

input: "hhhhhhapp"

output: ""

Question 72:Find the from and to index of the longest subarray with equal
number

of 0 and 1.

Input:
a =[1,1,0,0,1,0,0]

Output:

0 to 5

Input:

a =[1,1,1]

Output :

No index found

You might also like