[go: up one dir, main page]

0% found this document useful (0 votes)
47 views4 pages

ZScaler Questions

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)
47 views4 pages

ZScaler Questions

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/ 4

ZScaler

1. Ancestral Sorting
Input:
Given list of strings s[] = {“John VII”, David V, John V, Henry VI, Henry IV};
Output: {David V, Henry IV, Henry VI, John V, John VII}

2. There are some groups of devils and they split into people to kill them. Devils make
People on left to them, as their group and at last the group with maximum length will
be killed. Two types of devils are there namely “@” and “$”
People are represented as a string “P”
Constraints:
2<=Length of string<=10^9

Input:
PPPPPP@PPP@PP$PP
Output:
7

Explanation
4 groups can be formed
PPPPPP@
PPP@
PP$
PP
Most people in the group lie in group 1 with 7 members.

3. Raman was playing a game; he starts with x coins. Now in every step, he wins and
losses and he must get the money or pay the money as needed. He met a psychic
who can see the future and the Psychic predicted the outcomes after each step. Now
Raman wants to start the game with the minimum wage where he does not run out
of money. Help Raman to find what money he should start with. The only rule to
keep playing is not going in a credit situation.

Input Format:
First line with n, number of steps in the game
Next n lines, n integers denoting outcomes of every game. Positive means winning
and negative means losing that money.
Output Format:
One single integer denoting the minimum amount to start with

Constraints:
Number of steps<=10^9
-1000<=Money needed in each step<=1000

Sample Input:
4
2
-9
15
2

Sample Output:
7

Explanation:
If he starts with 7 rupees, then after steps: 7 ->9 -> 0-> 15 -> 17.

4. You have two numbers number1 and number2, your job is to check the number of
borrow operations needed for subtraction of number2 from number1. If the
subtraction is not possible then return the string not possible.

Input:
754 658
Output:
2

5. Given two strings st1 and st2, return the index of the first occurrence of st1 in st2, or
-1 if st1 is not part of st2.
Input: st2 = "sadbutsad", st1 = "sad"
Output: 0
Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we
return 0.

6. A prime number is a number which is divisible by one and itself. Also, a number is
called a good prime number if the sum of its digits is a prime number. For example a
number 23 is a good prime number because the sum of 2 and 3 (2+3=5) is 5 which is
a prime number. You are given an integer K. Your task is to find the kth good prime
number that is greater than a provided number N.

Input format:
The first line contains an integer N.
The next line contains an integer K.
Output format:
A single integer which is a Kth good prime number that is greater than a provided
number N.
Constraints:
1<=N<=10^5
1<=K<<=10^5

Sample Input:
44
Sample Output:
12
Explanation:
Good prime numbers starting from 4 are 5,7,11(1+1=2 which is prime
number),12(1+2=3 which is prime number),14(1+4=5 which is a prime number) and
so on. Because the sum of digits of an individual number is a prime number and 4th
good prime number is 12 in this series. Hence the output is 12.

7. Given a string and an integer k, find the number of substrings in which all the
different characters occur exactly k times.
Input: s = "aabbcc"
k=2
Output: 6
Explanation: The substrings are aa, bb, cc, aabb, bbcc and aabbcc.

8. Count the number of inversions in an array using merge sort.


Input: arr[] = {8, 4, 2, 1}
Output: 6
Explanation: Given array has six inversions: (8, 4), (4, 2), (8, 2), (8, 1), (4, 1), (2, 1).

9. Given a string date representing a Gregorian calendar date formatted as YYYY-MM-


DD, return the day number of the year.
Input: date = "2019-01-09"
Output: 9
Explanation: Given date is the 9th day of the year in 2019.

10. You are given two integer arrays nums1 and nums2, sorted in non-decreasing order,
and two integers m and n, representing the number of elements in nums1 and
nums2 respectively.
Merge them into a single array sorted in non-decreasing order.
The final sorted array should not be returned by the function, but instead be stored
inside the array nums1. To accommodate this, nums1 has a length of m + n, where
the first m elements denote the elements that should be merged, and the last n
elements are set to 0 and should be ignored. nums2 has a length of n.

Input: nums1 = [1,2,3], m = 3, nums2 = [2,5,6], n = 3


Output: [1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].

11. Given a list of strings words and a string pattern, return a list of words[i] that match
pattern. You may return the answer in any order.
A word matches the pattern if there exists a permutation of letters p so that after
replacing every letter x in the pattern with p(x), we get the desired word.
Recall that a permutation of letters is a bijection from letters to letters: every letter
maps to another letter, and no two letters map to the same letter.
Input: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
Output: ["mee","aqq"]
Explanation: "mee" matches the pattern because there is a permutation {a -> m, b ->
e, ...}.
"ccc" does not match the pattern because {a -> c, b -> c, ...} is not a permutation,
since a and b map to the same letter.

12. We define the usage of capitals in a word to be right when one of the following cases
holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "hostel".
Only the first letter in this word is capital, like "Google".
Given a string word, return true if the usage of capitals in it is right.
Input: word = "fLaG"
Output: false

You might also like