Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

SET B

1.You are given an array of non-overlapping intervals intervals where intervals[i] =


[starti,ZOHO QUESTIONS - SHORT PROGRAMMING endi] represent the start and
the end of the ith interval and intervals is sorted in ascending order by starti.
You are also given an interval newInterval = [start, end] that represents the start and
end of another interval.Insert newInterval into intervals such that intervals is still sorted
in ascending order by starti and intervals still does not have any overlapping intervals
(merge overlapping intervals if necessary).
Return intervals after the insertion.
Note that you don't need to modify intervals in-place. You can make a new array and
return it.

Constraints:
0 <= intervals.length <= 104
intervals[i].length == 2
0 <= starti <= endi <= 105
intervals is sorted by starti in ascending order.
newInterval.length == 2
0 <= start <= end <= 105

Testcase 1:
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]

Testcase 2:
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
Output: [[1,2],[3,10],[12,16]]
SET B

2.Write a program that receives a word A and some texts as input. You need to output
the texts (without modifying them) in the ascending order of the number of occurrences
of the word A in the texts. The input is as follows: an integer M(between 1 and 100,
inclusive), followed by the word A in the next line, and some text in each of the M next
lines.

Note: The texts and the word A contain only lowercase Latin letters (a,b,c…,z) and
blank spaces (“ ”). The maximum size of the texts and the word A is 100 Characters.
Every text has a different number of occurrences of the word A.

Note 2:you must print one text per line without modifying the texts.

Constraints:
1. The number of texts, M, must be between 1 and 100 inclusive.
2. Each text must not exceed 100 characters in length.
3. Each text and the word A must contain only lowercase Latin letters (a-z) and blank
spaces.
4. The word A must contain only lowercase Latin letters (a-z) and be at most 100
characters long.

Testcase 1

Input: 2
Java
I hate java
Python is a good programming language

Output: Python is a good programming language


I hate java
Testcase 2

Input: 3
python
I like to code in python
python is named after a show name monty python and not after the snake python
I think python is good i think python is important than php

Output:
i like to code in python
i think python is good i think python is important than php
python is named after a show name monty python and not after the snake python
SET B

3.Print the given pattern


Contraints :
The first line has one "1".
Each subsequent line represents the count of consecutive numbers in the previous line,
followed by that number.

Testcase 1:
input:
n=5
Output:
1
11
21
1211
111221

Testcase 2:

Input :
n=6
Output :
1
11
21
1211
111221
312211
SET B

4 .Write a program that takes an integer M and M integer array elements as input. The
program needs to find the minimum difference between two elements in the integer
array. The program then needs to print all those pairs of elements that have the
minimum difference. If more than one pair has the minimum difference, then the
program should print the output in the ascending order, if an element exists in two or
more pairs, then it should be printed two times or more.

Constraints:
1. The number of elements, M, must be between 1 and 100 inclusive.
2. Array elements must be between -10^9 and 10^9.

Testcase 1:
Input:
4
55 44 33 22
Output:
22 33 33 44 44 55

Explanation: The minimum difference between two elements is 11. Hence the pairs are
printed in the ascending order. Here 33 and 44 appear in two different pairs; hence both
are printed twice

Testcase 2:
Input:
5
10 20 15 25 30

Output:
10 15 15 20 20 25.
SET B

5.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.

Constraints:

1. The array must not contain any duplicate elements.


2. Array elements must be integers between -1000 and 1000.

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

Testcase 2:
Input: {10, 20, 30, 40, 50}
Output:{50, 10, 40, 20, 30}
SET B

6.Sliding Window
Given an array of numbers and a window of size k. Print the maximum of numbers
inside thewindow for each step as the window moves from the beginning of the array.

Input Format
Input contains the array size , no of elements and the window size

Output Format
print the maximum of numbers

Constraints
1 <= size <= 1000

Testcase 1:
Sample Input 1
8
13521869
3

Sample Output 1
555889
Explanation:
The first window: [1, 3, 5], maximum = 5
The second window: [3, 5, 2], maximum = 5
The third window: [5, 2, 1], maximum = 5
The fourth window: [2, 1, 8], maximum = 8
The fifth window: [1, 8, 6], maximum = 8
The sixth window: [8, 6, 9], maximum = 9
Testcase 2
Input:
10
1 2 3 4 5 6 7 8 9 10
5

Output:
5 6 7 8 9 10

Explanation:

The first window: [1, 2, 3, 4, 5], maximum = 5


The second window: [2, 3, 4, 5, 6], maximum = 6
The third window: [3, 4, 5, 6, 7], maximum = 7
The fourth window: [4, 5, 6, 7, 8], maximum = 8
The fifth window: [5, 6, 7, 8, 9], maximum = 9
The sixth window: [6, 7, 8, 9, 10], maximum = 10
SET B

7. NEXT PALINDROME
You're given a positive integer n. Your task is to find the smallest palindrome greater
than n.
A palindrome is a number that reads the same backward as forward.

Input Format:
A single positive integer

Output Format:
The smallest palindrome greater than n.

Constraints:
1<=n<=10^9

Testcase 1:
Sample Input 1:
123

Sample Output 1:
131

Testcase 2:
Sample Input 1:
9687

Sample Output 1:
9779
SET B

8.Problem Description:
Given a sentence, find and print the words that are not palindromes.

Input:
A sentence consisting of lowercase alphabets and spaces.

Output:
A string containing the non-palindrome words separated by spaces.

Testcase 1:
Input 1:
he knows malayalam

Output:
he knows

Testcase 2:
Input 2:
The racecar zoomed past the finish line

Output:
The zoomed past the finish line
SET B

9.Sorting:
Problem Description:
You are given an array of integers. Sort the odd numbers in ascending order and even
numbers in descending order, and then merge them into a single array.

Constraints:
The array contains integers only.
The array can have duplicates.
The array can have both positive and negative numbers.
The length of the array is between 1 and 10^5.

Testcase 1:
Input 1:
[5, 8, 11, 6, 2, 1, 7]

Output 2:
[1, 5, 7, 11, 8, 6, 2]

Testcase 2:
Input 2:
[9, 3, 12, 5, 7, 10]

Output:
[3, 5, 7, 12, 10, 9]
SET B

10. Ninja is shifting to a new place named NinjaGram. To take admission to the new
school, the teacher gives him a sentence and asks him to check whether the sentence
is a pangram.

A word or a sentence is called a pangram if it contains all the English alphabet letters.

Since Ninja is new to programming, he doesn’t have much experience; he asks you to
solve the problem. Can you help Ninja figure out whether the sentence is a pangram?
Constraints:
1<= T <= 50
1<= n <= 10^4

Where ’T’ is the number of test cases, ‘n’ denotes the number of characters in the
string.

Testcase 1:

Sample Input 1:
2
12
toosmallword
35
TheQuickBrownFoxJumpsOverTheLazyDog

Sample Output 1:
NO
YES

Explanation for Sample Input 1:


In the first test case, the given string is “toosmallword” which contains the characters
[‘t’,’o’,’s’,’m’,’a’,’l’,’w’,’r’,’d’], which doesn’t contain all the 26 alphabetic characters.
Hence the answer is “NO”.
In the second test case, the given string is
“TheQuickBrownFoxJumpsOverTheLazyDog” which contains the characters:
[‘t’,’h’,’e’,’q’,’u’,’i’,’c’,’k’,’b’,’r’,’o’,’w’,’n’,’f’,’x’,’j’,’m’,’p,’’s’,’v’,’l,’a’,’z’,’y’,’ d’,’g’], which contains
all the 26 alphabetic characters. Hence the answer is “YES”.

Testcase 2:

Sample Input 2:
2
16
CodingNinjas
10
CodeStudio

Sample Output 2:
NO
NO

Explanation for Sample Input 2:


In the first test case, the given string is “CodingNinjas” which contains the characters
[‘c’,’o’,’d’,’i’,’n’,’g’,’i’,’j’,’a’,’s’], which doesn’t contain all the 26 alphabetic characters.
Hence the answer is “NO”.

In the first test case, the given string is “CodeStudio” which contains the characters
[‘c’,’o’,’d’,’e’,’s’,’t’,’u’,’i’], which doesn’t contain all the 26 alphabetic characters. Hence
the answer is “NO”.

You might also like