Z0ho Basic Programming Round 2 Online Question Set
Z0ho Basic Programming Round 2 Online Question Set
Z0ho Basic Programming Round 2 Online Question Set
Question 1
Your task is to complete a function “count_heads()” that takes two inputs N and
R. The function should return the probability of getting exactly R heads on N
successive tosses of a fair coin. A fair coin has an equal probability of landing a
head or a tail (i.e. 0.5) on each toss.
Example 1
Input: 1 1
Output: 0.500000
Example 2
Input: 4 3
Output: 0.250000
Question 2
Write a program that will print the sum of diagonal elements of a 10X10 matrix.
The program will take a total of 100 numbers as input (10 numbers will be input
per line and each number will be separated by a space).
Example 1
Input: 1 2 3 4 5 6 7 8 9 0
0123456780
3456789640
2345678932
3456743213
3456244246
2346246235
2356246235
2462143352
3352462146
Output: 42
Example 2
Input: 1 22 33 44 55 66 77 88 99 100
100 1 88 77 66 55 44 33 22 11
88 88 1 66 55 44 33 22 11 100
88 77 66 1 44 33 22 11 100 99
77 66 55 44 1 22 11 88 99 100
66 55 44 33 22 1 77 88 99 100
44 33 22 11 100 99 1 77 66 55
33 22 11 100 99 88 77 1 55 44
22 11 100 99 88 77 66 55 1 33
100 11 22 33 44 55 99 88 77 1
Output: 10
Question 3
Write a program that will take one string as input. The program will then remove
vowels a, e, i, o, and u (in lower or upper case ) from the string. If there are two
or more vowels that occur together then the program shall ignore all of those
vowels.
Example 1
Input: Cat
Output: Ct
Example 2
Input: Compuuter
Output: Cmpuutr
Question 4
Write a program that will take a string as input. The program will then determine
whether each left parenthesis ‘(’ has a matching right parenthesis ‘)’ and also all
the ‘)’ has a consecutive ‘(‘. If so, the program will print 0 else the program will
print 1.
Example 1
Example 2
Input: (9*(7-2)*(1*5)
Output: 0
Question 5
Write a program to find out and display prime numbers from the given list of
integers. The program will accept input in two lines. First-line contains a
number indicating the total number of integers in the list and the second line
contains integers separated by spaces.
Example 1
Input: 5
46937
Output: 3 7
Example 2
Input: 10
8 10 3 12 7 15 11 2 17 26
Output: 3 7 11 2 17
Question 6
Write a program that will take a number as input. The program will convert the
inputted number to a format, which will contain an integer part and a fraction
part. The fraction part needs to be reduced to its lowest representation. The
input will not contain any repeating decimals e.g. 1.3333…33. The output will be
:
Example 1
Input: 2.95
Output: 2 19/20
Example 2
Input: 3.08
Output: 3 2/25
Question 7
Example 2
Question 8
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.
Example 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.
Example 2
Input: 5
1 99 22 44 1001
Output: 1 22
Question 9
Example 1
Input: 0
Output: 0
Example 2
Input: 1
Output: 1
Question 10
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.
Example 1
Input: 2
Java
I hate java
Python is a good programming language
Output: Python is a good programming language
I hate java
Example 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
Question 11
Given a sorted array A, find the size of array A after removing the duplicate
elements.
Examples:
A: [1 2 3 3 3 4 5 5]
Testing
Input Format
The first line contains an integer ‘T’ denoting the number of test cases.
Output format
For each test-cases, the output has a line with an integer ‘len’ denoting the
length of the resultant array.
Sample Input
11122
133344
Expected Output
Constraints
Questions 12
Given an array A[] consisting of only 0s, 1s, and 2s. The task is to sort the array,
i.e., put all 0s first, then all 1s and all 2s in last.
This problem is the same as the famous “Dutch National Flag problem”. The
problem was proposed by Edsger Dijkstra. The problem is as follows:
Given N balls of colour red, white or blue arranged in a line in random order. You
have to arrange all the balls such that the balls with the same colours are
adjacent with the order of the balls, with the order of the colours being red,
white and blue (i.e., all red coloured balls come first then the white coloured
balls and then the blue coloured balls).
Exmple:
Input: {0, 1, 2, 0, 1, 2}
Output: {0, 0, 1, 1, 2, 2}
Explanation: {0, 0, 1, 1, 2, 2} has all 0s first, then all 1s and all 2s in last.
Input: {0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1}
Output: {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2}
Explanation: {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2} has all 0s first, then all 1s and all 2s in
last.
Questions 13
Test cases:
Case1:
N=6,X=4,Y=10
A=4,3,7,11,50,1
Output:7
Case 2:
N=6,X=10,Y=14
A=4,3,7,11,50,1
Output:11
Case 3:
N=11,X=50,Y=100
A=21,63,54,67,13,88,43,57,604,1,100
Output:63,54,67,88,57
Given an array of integers, replace every element with the next greatest
element (greatest element on the right side) in the array. Since there is no
element next to the last element, replace it with -1. For example, if the array is
{16, 17, 4, 3, 5, 2}, then it should be modified to {17, 5, 5, 5, 2, -1}.
Example :
Output: 3
4. In MS-Paint, when we take the brush to a pixel and click, the color of the
region of that pixel is replaced with a new selected color. Following is the
problem statement to do this task.
Given a 2D screen, location of a pixel in the screen and a color, replace color of
the given pixel and all adjacent same colored pixels with the given color.
Example:
Input:
{1, 1, 1, 1, 1, 1, 0, 0},
{1, 0, 0, 1, 1, 0, 1, 1},
{1, 2, 2, 2, 2, 0, 1, 0},
{1, 1, 1, 2, 2, 0, 1, 0},
{1, 1, 1, 2, 2, 2, 2, 0},
{1, 1, 1, 1, 1, 2, 1, 1},
{1, 1, 1, 1, 1, 2, 2, 1},
};
x = 4, y = 4, newColor = 3
Output:
{1, 1, 1, 1, 1, 1, 0, 0},
{1, 0, 0, 1, 1, 0, 1, 1},
{1, 3, 3, 3, 3, 0, 1, 0},
{1, 1, 1, 3, 3, 0, 1, 0},
{1, 1, 1, 3, 3, 3, 3, 0},
{1, 1, 1, 1, 1, 3, 1, 1},
{1, 1, 1, 1, 1, 3, 3, 1},
};
5. Given a matrix of 2D array of n rows and m coloumns. Print this matrix in ZIG-
ZAG fashion as shown in figure.
Example:
Input:
123
456
789
Output:
124753689
Testcase 1:
Input: Java1234
Testcase 2:
Input: Python1223:
Output: Python1234 (Replace the second 2 with 3, and replace 3 with 4 as 3 is
replaced for the duplicated 2)
Testcase 3:
Input: aBuzZ9900
Output: aBuzC9012
(Replace the second ‘Z’ with ‘C’ as ‘a’ and ‘B’ are already there in the String.
Replace with capital C as the letter to be replaced is capital Z. The second 9
turns out to be zero and the zero turns out to ‘1’ and the second zero turns out
to ‘2’)
8. Q2. Print all possible subsets of the given array whose sum equal to given N.
example: Input: {1, 2, 3, 4, 5} N=6 Output: {1, 2, 3}, {1, 5}, {2, 4}
9. Reverse the words in the given String1 from the first occurrence of String2 in
String1 by maintaining white Spaces.
example: String1 = Input: This is a test String only String2 = st Output: This is a
only String test
10. calculate Maximum number of chocolates can eat and Number of wrappers
left in hand.
Max visit: Maximum number of times one can visit the shop.(if zero consider it
infinite)
example: input: Money:40 Price:1 wrappers:3 choco:1 Max visit:1 Output: total
chocolate can eat: 53 wrappers left in hand:14
11.
Sample Input-
Hacker
Rank
Sample Output-
Hce akr
Rn ak
2.
Sample Input-
Sample Output-
P P
R R
O O
R R
A A
M M
14.
Input: {1, 2, 3, 4, 5, 6, 7}
output: {7, 1, 6, 2, 5, 3, 4}
16.Assume there exists infinite grid, you’re given initial position x, y. Inputs will
be movements either L or R or U or D. After n inputs, you need to give the
current position.
• Input:
• 4 5 //initial position x, y
• 9 //number of movements
• U L R R D D U L R //7 movements
• Output:
55
• Given a matrix NxN, you are initially in the 0, 0 position. The matrix is filled
with ones and zeros. Value “one” represents the path is available, while “zero”
represents the wall. You need to find the can you able to reach the (N-1)x(N-1)
index in the matrix. You can move only along the right and down directions if
there’s “one” available.
• Input:
• 5 //N value
• 10100
• 11111
• 00010
• 10111
• 01101
• Output:
Yes
17.Given an array of integers, compute the maximum value for each integer in
the index, by either summing all the digits or multiplying all the digits. (Choose
which operation gives the maximum value)
• Input:
• 5
• 120 24 71 10 59
• Output:
• 3 8 8 1 45
Explanation: For index 0, the integer is 120. Summing the digits will give 3, and
whereas Multiplying the digits gives 0. Thus, maximum of this two is 3.
. 18. -1 represents ocean and 1 represents land find the number of islands in the
given matrix.
1 -1 -1 1
-1 1 -1 1
-1 -1 1 -1
-1 -1 -1 1
19. Print all the possible subsets of array which adds up to give a sum.
sum=10
Output: {2, 3, 5}
{2, 8}
{10}
20. There is a circular queue of processes. Every time there will be certain no of
process skipped and a particular start position. Find the safe position.
Start position:3
Skip: 2nd
21.Given N. print the following snake pattern (say N = 4). condition: must not
use arrays ( 1D array or 2D array like Matrix ).
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
22.Given N. print the Latin Matrix (say N = 3). condition: must not use
strings(aka character literals), arrays (both 1D and 2D), inbuilt functions(like
rotate).
A B C
B C A
C A B
23. Given a number N. find the minimum count of numbers in which N can be
represented as a sum of numbers x1, x2, … xn. where xi is number whose digits
are 0s and 1s.
example 1) i/p : N = 33
25. Given an array of integers, write a program to re-arrange the array in the
given form.
26.Sort the given elements in decending order based on the number of factors
of each element – Solution 1
27.Find whether the given number is palindrome or not. Don’t use arrays or
strings
28.Reverse the given string keeping the position of special characters intact
29.Find the shortest path from one element to another element in a matrix
using right and down moves alone. The attached solution uses moves in all
directions. – Solution 4
30.Pattern
Check whether all english alphabets are present in the given sentence or not
O/P: True
O/P: False
Four rules were given based on the type and no. of characters in the string.
Given two strings, find the first occurrence of all characters of second string in
the first string and
print the characters between the least and the highest index
O/P: OHOCORPORAT
So print the characters of the first string in this inex range i.e. OHOCORPORAT
Given a matrix print the largest of the sums of the two triangles split by
diagonal from top right to bottom left
I/P:
33
123
456
789
O/P: 38
I/P: 4
3542
245
45678
4921
12
O/P: 50856
Problem 36:
Many students will able to solve 3 problems in this round. So make sure you
stand apart from the crowd.Their vacancy is going to be 5 for a team. The
performance in this round could be taken as a tie breaker for round 3.
input : aaabbcc
output : abc
Problem 37.:
Evaluate the expression and sort and print the output. Getting the input is the
tricky part
Input:
Number of input : 4
2*3
2^2^2
35
3*1
Output:
3*1
2*3
2^2^2
35
Problem 38:
Given a 6 blocks, of different height h1, …, h6 . Make 2 towers using 3 Blocks for
each tower in desired height h1, h2. Print the blocks to be used in ascending
order
Input:
12543 6
height of tower: 6 15
Output :
123&456
Problem 39:
Given a 5X5 chess board as input. 9 knights are placed in the board. Print
whether the configuration valid or Invalid.
Problem 40:
Given a number, print all the code that can be formed with z={a=1, .., z=26}.
1123
{1, 1, 2, 3} = aabc
{11, 2, 3} = kbc
42. Given an array of integers of size n. Convert the array in such a way that if
next valid number is same as current number, double its value and replace the
next number with 0. After the modification, rearrange the array such that all 0’s
are shifted to the end.
Output : 4 4 8 0 0 0
Output : 4 2 12 8 0 0 0 0 0 0
Input : 97
number.
44.Given an array A[] and a number x, check for pair in A[] with sum as x.
Eg : Input {1, 2, 4, 3, 5, 6}
SUM : 5
***
*****
***
46. Given a text and a wildcard pattern, implement wildcard pattern matching
algorithm that finds if wildcard pattern is matched with text. The matching
should cover the entire text (not partial text).
The wildcard pattern can include the characters ‘?’ and ‘*’
Example:
Text = “baaabab”,
Pattern = “*****ba*****ab”,
output : true
47. Given an input string and a dictionary of words, find out if the input string
can be segmented into a space-separated sequence of dictionary words. See
following examples for more details.
Input: ilike
Output: Yes
Input: ilikesamsung
Output: Yes
32
654
10 9 8 7
10 9 8 7
654
32
49.Given an array as input, The condition is if the number is repeated you must
add the number and put the next index value to 0. If the number is 0 print it at
the last.
Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8}
Output: 4 2 12 8 0 0 0 0 0 .
49. Given two Strings s1 and s2, remove all the characters from s1 which is
present in s2.
output: s1=”exprIece”
50.Find the next greater element for each element in given array.
If we are solving this question using sorting, we need to use any O(nlogn)
sorting algorithm.
https://www.geeksforgeeks.org/distinct-permutations-string-set-2
53.Given an array with repeated numbers, Find the top three repeated
numbers.
output: 3, 16, 15
54.Given two dimensional matrix of integer and print the rectangle can be
formed using given indices and also find the sum of the elements in the
rectangle
Output:
Rectangle
46755
24894
sum 54
55. Find the result subtraction, multiplication, division of two integers using +
operator.
Input: 6 and 4
output:
Input : -8 and -4
Output:
56..Given a sentence of string, in that remove the palindrome words and print
the remaining.
Input:
Output:
He good
Input:
Output:
Hari speaks
Output: 29
Output: 0
Output: 1461
58.
Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the
number of possible decodings of the given digit sequence.
Examples:
Ex I/p abcccccbba
O/p 8 (from a to a)
I/p aaaaaaaa
O/p 6
61..sort the array odd numbers in ascending and even numbers in descending.
I/p 5 8 11 6 2 1 7
O/p 1 5 7 11 8 6 2
62. It’s about anagram.i/p was array of strings .and a word was given to find
whether it has anagram in given array.
Word: ate
63.array of numbers were given to find a number which has same sum of
numbers in it’s either side.
I/p 1, 2, 3, 7, 6
65.prime factor – sort the array based on the minimum factor they have.
66.adding a digit to all the digits of a number eg digit=4, number = 2875, o/p=
612119
68.lexicographic sorting.
69.given a set of numbers, and a digit in each iteration, if the digit exists in any
of the numbers, remove its occurrences and ask for the next digit till the list
becomes empty.
[ 10, 5, 30, 20 ]
Input : [ -1, 0, 3, 2 ]
[ 3, 4, 0, -1, 2 ]
72. Find the least prime number that can be added with first array element that
makes them divisible by second array elements at respective index (check for
prime numbers under 1000, if exist return -1 as answer) & (Consider 1 as prime
number)
Input : [ 20, 7 ]
[ 11, 5 ]
Output : [ 1, 3 ]
Explanation :
(20 + ?) % 11
( 7 + ?) % 5
73. Sort the array elements in descending order according to their frequency of
occurrence
Input : [ 2 2 3 4 5 12 2 3 3 3 12 ]
Output : 3 3 3 3 2 2 2 12 12 4 5
Input : [ 0 -1 2 1 0 ]
Output : 0 0 -1 1 2
Note : sort single occurrence elements in ascending order
74. Print true if second string is a substring of first string, else print false.
Example :
Input: 1 1 2 3 1 2 4
Output: 2
Example:
Input: 2 10 4 8
Output: 2 8
Input: 1 10 6 8 13 21
Output: 1 8 13 21
Example:
Input: 1
Output: 0
Input: 2
Output:
00
01
10
11
Input: 3
Output:
000
001
010
011
100
101
110
111
You have to go from starting point to ending point. One valid solution is enough.
Example:
Input:
N=4
1100
1001
1111
0001
Output:
_100
_001
____
000_
Example:
Input:
Number of bits: 12
Bits: 1 0 1 1 0 1 1 0 1 1 1 1
Consecutive K: 2
Output:
1011001100110110
81. Print the total number of odd and even digits in the given number.
Output : ODD 4
EVEN 3
Ex. INPUT :
Size of Array : 8
OUTPUT :
Ex. INPUT :
Size of Array : 4
OUTPUT :
Ex. INPUT :
Size of Array : 1
OUTPUT :
No second maximum
83. Print the following pattern
Ex. INPUT : 5
OUTPUT :
11
121
1331
14641
Ex. INPUT : 7
OUTPUT :
11
121
1331
14641
1 5 10 10 5 1
1 6 15 20 15 6 1
84. Given a two dimensional array which consists of only 0’s and 1’s. Print the
matrix without duplication.
Ex. INPUT :
Enter Row Size : 4
101
110
111
101
OUTPUT :
Unique Matrix :
101
110
111
85. Given an array of positive numbers. Print the numbers which have longest
continuous range.
Ex. INPUT :
OUTPUT :
1234
Ex. INPUT :
OUTPUT :
1234
6789
Input :
OUTPUT :
123457
INPUT :
OUTPUT :
124
88. Given an array of numbers and a number k. Print the maximum possible k
digit number which can be formed using given numbers.
INPUT :
OUTPUT :
974
INPUT :
OUTPUT :
98973
89. Given an array of numbers and a window of size k. Print the maximum of
numbers inside the window for each step as the window moves from the
beginning of the array.
INPUT :
OUTPUT :
555889
90: Given a string, reverse only vowels in it; leaving rest of the string as it is.
Input : abcdef
Output : ebcdaf
91 : Write a program to check if the given words are present in matrix given
below. The words can be left to right, top to bottom and the diagonals (in top to
bottom direction)
92 : Write a program to form lines using given set of words. The line formation
should follow below rules.
i) Total characters in a single line excluding the space between the words and
the favorite character should not exceed the given number.
Loving, Mango
Eating Mango
Loving Pogo.
Given 2 huge numbers as separate digits, store them in array and process them
and calculate the sum of 2 numbers and store the result in an array and print
the sum.
Input:
Number of digits:12
928135673116
Number of digits:9
784621997
Output :
928920295113
value
Input
Array = {1 3 4 8 10 } N = 7
output
true
Input x = 30 n = 10
output = 0.5
Input: 3 , 4
Output 12
{-2 -3 4 -1 -2 1 5 -3}
output 7 elements [ 4 -1 -2 1 5]
98. Given unsorted array find all combination of the element for a given sum.
Order should be maintained.
Input :
8 3 4 7 9 N=7
Output
{3 4 } {7}
99. Given an odd length word which should be printed from the middle of the
word.
Example:
Input: PROGRAM
Output:
G
GR
GRA
GRAM
GRAMP
GRAMPR
GRAMPRO
101. Given a few pairs of names in the order child, father. The input is a person
name and level number. The output should be the number of children in that
particular level for the person given.
Example:
Input:
{Ram, Syam},
{Akil, Syam},
{Nikil, Ram},
{Subhash, Ram},
{Karthik, Akil}
];
Syam 2
Output: 3 (Syam has Ram and Akil in level 1 and in level 2 he have Nikil,
Subhash, Karthik. So the answer is 3).
101 Given an array of positive integers. The output should be the number of
occurrences of each number.
Example:
Input: {2, 3, 2, 6, 1, 6, 2}
Output:
1–1
2–3
3–1
6–2
102) Given an array, find the minimum of all the greater numbers for each
element in the array.
Sample:
Output:
103) Find the largest sum contiguous subarray which should not have negative
numbers. We have to print the sum and the corresponding array elements
which brought up the
sum.
Sample:
Output:
Sum : 14
Elements : 3, 2, 9
104) Given a string, we have to reverse the string without changing the position
of punctuations and spaces.
105) Given a 2D grid of characters, you have to search for all the words in a
dictionary by
moving only along two directions, either right or down. Print the word if it
occurs.
Sample :
a z o l
n x h o
v y i v
o r s e
Output:
zoho
love
Is
106) Given a string, change the order of words in the string (last string should
come first).
Find the Total Number of Positive, Negative, and Neutral Numbers in an Array:
Write a program to find and print the ratio of positive, negative, and neutral
numbers in a given array.
Write a program to find out and display prime numbers from a given list of
integers. The program will accept input in two lines. The first line contains a
number indicating the total number of integers in the list and the second line
contains the integers separated by spaces.
String Compression:
Balanced Parentheses:
Write a function that takes an array of integers and a target sum, and returns
indices of the two numbers such that they add up to the target sum.
Merge Intervals:
Matrix Rotation:
Palindrome Check:
Fibonacci Sequence:
Binary Search:
Maximum Subarray:
Find the contiguous subarray within an array that has the largest sum.
Anagram Check:
Write a function to merge two sorted arrays into one sorted array.
SET 1:
1. Pangram Checking
Check whether all english alphabets are present in the given sentence or not
O/P: True
O/P: False
2. Password Strength
Find the strength of the given password string based on the conditions
Four rules were given based on the type and no. of characters in the string.
3. First Occurrences
Given two strings, find the first occurrence of all characters of second string in
the first string and
print the characters between the least and the highest index
So print the characters of the first string in this inex range i.e. OHOCORPORAT
Given a matrix print the largest of the sums of the two triangles split by
diagonal from top right to bottom left
I/P:
33
123
456
789
O/P: 38
5. Matrix Addition
I/P: 4
3542
245
45678
4921
12
O/P: 50856
6. Cricket Scores
Given a timeline of scores, find the individual scores of player 1 and player 2
and Extras
I/P:
1.2.436W1.N.21
O/P:
P1 – 8
P2 – 12
Extras – 2
7. Queries
RABC
1 56 67 89
2 89 54 90
3 78 91 83
4 69 72 95
Given the above matrix, print the result of the queries given the following
syntax.
The first input string has a single character denoting the field to be printed.
= – Equal to
I/P: *
A>70
O/P:
2 89 54 90
3 78 91 83
4 69 72 95
I/P: A
C<90
O/P:
56
78
Given a N*N binary matrix and the co-ordinate points of start and destination,
find the number of possible path between them.
I/P:
1001
1010
1110
0111
1 2 (start position)
0 0 (destination)
O/P: 2
I/P:
1001
1010
1110
0111
2 0 (start position)
3 3 (destination)
O/P: 2
9. Shuffle an Array
Given a range of numbers print the numbers such that they are shuffled
I/P:
1 10
5 12
1 10
O/P: (The order of numbers may vary)
2 3 9 5 1 10 6 7 8 4
5 6 9 12 10 11 7 8
9 5 1 2 3 4 8 7 6 10
If any of the given ranges are same, The orders of the numbers must vary.
I/P: 4
17
17
17
17
O/P:
6715234
1726354
6351427
1236574
SET 2:
1.Given two dimensional matrix of integer and print the rectangle can be
formed using given indices and also find the sum of the elements in the
rectangle
Output:
Rectangle
46755
24894
sum 54
Input: 6 and 4
output:
Input : -8 and -4
Output:
3.Given a sentence of string, in that remove the palindrome words and print the
remaining.
Input:
Output:
He good
Input:
Output:
Hari speaks
Output: 29
Output: 0
Output: 1461
5. Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the
number of possible decodings of the given digit sequence.
Examples:
SET 3:
Ex I/p abcccccbba
O/p 8 (from a to a)
I/p aaaaaaaa
O/p 6
2.sort the array odd numbers in ascending and even numbers in descending.
I/p 5 8 11 6 2 1 7
O/p 1 5 7 11 8 6 2
3. It’s about anagram.i/p was array of strings .and a word was given to find
whether it has anagram in given array.
Word: ate
4.array of numbers were given to find a number which has same sum of
numbers in it’s either side.
I/p 1, 2, 3, 7, 6
SET 4:
Input:
15
Output:
3,5,7,9,11,13
2) To find the factors of the numbers given in an array and to sort the numbers
in descending order according to the factors present in it.
Input:
Output:
12, 16, 8, 2, 3
Input: 234
Op:
11
21
1211
111221
5) A man his driving car from home to office with X petrol. There are N number
of petrol bunks in the city with only few capacities and each petrol is located in
different places For one km one liter will consume. So he fill up petrol in his
petrol tank in each petrol bunks. Output the remaining petrol if he has or tell
him that he cannot travel if he is out of petrol.
Input:
Petrol bunks: A B C
Input:
N= 3, M=3
Output:
XXX
X0X
XXX
Input:
N=4 M=5
Output:
XXXX
X00X
X00X
X00X
XXXX
Input:
N=6 M=7
XXXXXX
X0000X
X0XX0X
X0XX0X
X0XX0X
X0000X
XXXXXX
Explanation: 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.
Input:
Array: 3, 9, 7, 4, 6, 8
X: 3
Output:
3, 9
3, 6
9, 6
3, 9, 6
No of groups: 4
SET 5:
2.prime factor – sort the array based on the minimum factor they have.
3.adding a digit to all the digits of a number eg digit=4, number = 2875, o/p=
612119
form the largest possible number using the array of numbers.
4.lexicographic sorting.
5.given a set of numbers, and a digit in each iteration, if the digit exists in any of
the numbers, remove its occurrences and ask for the next digit till the list
becomes empty.
SET 6:
[ 10, 5, 30, 20 ]
Input : [ -1, 0, 3, 2 ]
[ 3, 4, 0, -1, 2 ]
2. Find the least prime number that can be added with first array element that
makes them divisible by second array elements at respective index (check for
prime numbers under 1000, if exist return -1 as answer) & (Consider 1 as prime
number)
Input : [ 20, 7 ]
[ 11, 5 ]
Output : [ 1, 3 ]
Explanation :
(20 + ?) % 11
( 7 + ?) % 5
3. Sort the array elements in descending order according to their frequency of
occurrence
Input : [ 2 2 3 4 5 12 2 3 3 3 12 ]
Output : 3 3 3 3 2 2 2 12 12 4 5
Input : [ 0 -1 2 1 0 ]
Output : 0 0 -1 1 2
4. Print true if second string is a substring of first string, else print false.
SET 7:
1) Given an array, find the minimum of all the greater numbers for each element
in the array.
Sample:
Output:
2) Find the largest sum contiguous subarray which should not have negative
numbers. We have to print the sum and the corresponding array elements
which brought up the sum.
Sample:
Output:
Sum : 14
Elements : 3, 2, 9
3) Given a string, we have to reverse the string without changing the position of
punctuations and spaces.
4) Given a 2D grid of characters, you have to search for all the words in a
dictionary by
moving only along two directions, either right or down. Print the word if it
occurs.
Sample :
azol
nxho
vyiv
orse
Output:
zoho
love
Is
5) Given a string, change the order of words in the string (last string should
come first).
SET 8:
Program 1:
Input:
Output:
Program 2:
Input:
With the starting and ending time of work given find the minimum no of workers
needed
1230 0130
1200 0100
1600 1700
Output:
Program 3:
Find the union intersection of two list and also find except (remove even
elements from list1 and odd elements from list2)
Input
List 1: 1,3,4,5,6,8,9
List 2: 1, 5,8,9,2
Union: 1, 3,4,5,6,8,9,2
Intersection: 1,5,8,9
Except: 1, 3, 5,9,8,2
Program 4:
Input
123
456
789
Output:
412
753
896
Input:
1234
5678
9 10 11 12
13 14 15 16
Output:
5123
9 10 6 4
13 11 7 8
14 15 16 12
Program 5:
Input
4691
Output:
9461
SET 9:
The wildcard pattern can include the characters ‘?’ and ‘*’
Example:
Text = “baaabab”,
Pattern = “*****ba*****ab”,
output : true
2. Given an input string and a dictionary of words, find out if the input string can
be segmented into a space-separated sequence of dictionary words. See
following examples for more details.
Input: ilike
Output: Yes
Input: ilikesamsung
Output: Yes
32
654
10 9 8 7
10 9 8 7
654
32
4.Given an array as input, The condition is if the number is repeated you must
add the number and put the next index value to 0. If the number is 0 print it at
the last.
Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8}
Output: 4 2 12 8 0 0 0 0 0 .