Skill Rack
Skill Rack
Boundary Condition(s):
1 <= N <= 999999999999999
Input Format:
The first line contains the value N.
Output Format:
The first line contains the digits having odd adjacent digits.
Example Input/Output 1:
Input:
2353176
Output:
25316
Example Input/Output 2:
Input:
386369725
Output:
62
The program must accept an integer N as the input. The
program must print the digits surrounded by even digits on
both sides. The first and last digits have only one digit
adjacent digit to them. So consider only the single adjacent
digit for them. If there is no digit surrounded by even digits,
then the program must print -1 as the output.
Example Input/Output 1:
Input: 14689025
Output: 1695
Example Input/Output 2:
Input: 1357935
Output: -1
The program must accept an integer N the input. The program
must print the desired pattern as shown in the Example
Input/Output section.
Example Input/Output 1:
Input: 8
Output: 1000
0**0
0**0
0001
Example Input/Output 2:
Input: 7
Output: 111
1*1
111
'''
Adjacent Even Digits
The program must accept an integer N as the input. The program must
print the digits surrounded by even digits on both sides. The first and
last digits have only one digit adjacent digit to them. So consider only
the single adjacent digit for them. If there is no digit surrounded by even
digits, then the program must print -1 as the output.
Boundary Condition(s):
11 <= N <= 999999999
Input Format:
The first line contains the value N.
Output Format:
The first line contains either the digits having even adjacent digits or -1.
Example Input/Output 1:
Input:
14689025
Output:
1695
Example Input/Output 2:
Input:
1357935
Output:
-1
'''
The program must accept an integer N as the input. The program
must print the 4-bit binary representation of each digit in N as the
output.
Example Input/Output 1:
Input: 4653
Output: 0100
0110
0101
0011
Example Input/Output 2:
Input: 102
Output: 0001
0000
0010
The program must accept an integer N the input. The program
must print the desired pattern as shown in the Example
Input/Output section.
Example Input/Output 1:
Input: 8
Output: 1000
0**0
0**0
0001
Example Input/Output 2:
Input: 7
Output: 111
1*1
111
The program must accept an integer N as the input. The program
must print the 4-bit binary representation of each digit in N as the
output.
Example Input/Output 1:
Input: 4653
Output: 0100
0110
0101
0011
Example Input/Output 2:
Input: 102
Output: 0001
0000
0010
Alphabet Adjacent Pairs in Sequence
Accept a string S which contains only lower case alphabets and print the
count of instances C where in a pair of adjacent characters, the right
character is next to the left character in the original alphabetical sequence.
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the integer value C
Example Input/Output 1:
Input:
abegh
Output:
2
Explanation:
ab gh are the two instances.
Example Input/Output 2:
Input:
abcdef
Output:
5
Explanation:
ab bc cd de ef are the five instances.
The program must accept a string S as the input. The program
must break the string into multiple string values so that each string
contains exactly one vowel. The string values must be broken such
that all the string values start with vowel except for the first string.
Example Input/Output 1:
Input: helloworld
Output: hell
ow
orld
string.
Example Input/Output 2:
Input: daefifof
Output: da
ef
if
of
The program must accept an integer array of size N containing only
0's and 1's as the input. The program must bring all the zeros to the
front and all the ones to the end of the array. Then the program must
print the modified array as the output.
Example Input/Outupt 1:
Input: 7
0110100
Output: 0 0 0 0 1 1 1
Example Input/Outupt 2:
Input: 4
1110
Output: 0 1 1 1
The program must accept three floating point values as G
(gravitational constant), M (mass) and R (radius) of a planet.
The program must calculate and print the escape speed of the
object with precision up to 3 decimal places.
Example Input/Output 1:
Example Input/Output 2:
Example Input/Output 1:
Input: 5
Output: 3 2 1 1 0
Example Input/Output 2:
Input: 12
Output: 89 55 34 21 13 8 5 3 2 1 1 0
the program must accept an integer n as the input. the program
must print the first occurring consecutive odd digits if the first digit
is odd as the output. else the program must print the first occurring
consecutive even digits as the output.
example input/output 1:
input: 157894
output: 157
example input/output 2:
input: 601648
output: 60
The program must accept two integers N and X as the input. The
program must print the integers from 1 to N which contains the
digit X. If there is no such integer then the program must print "-1"
as the output.
Example Input/Output 1:
Input: 40 7
Output: 7 17 27 37
Example Input/Output 2:
Input: 5 9
Output: -1
Alphabets Plus Digits Sum
The program must accept a string S which has alphabets and digits as
the input. The program must find the sum of all the digits as D. Then
the program must print the alphabets which are D positions from the
alphabets present in the string.
Note:
The output must be in lowercase.
Boundary Condition(s):
Length of the S is from 3 to 100.
Input Format:
The first line contains the string S.
Output Format:
The first line contains the modified alphabets.
Example Input/Output 1:
Input:
435acl
Output:
mox
Explanation:
The digits are 4, 3, 5. The sum = 4 + 3 + 5 = 12.
The alphabets are a, c, l. So a + 12 = m, c + 12 = o, l + 12 = x.
Example Input/Output 2:
Input:
1121ZU
Output:
ez
Explanation:
The digits are 1, 1, 2, 1. The sum = 1 + 1 + 2 + 1 = 5.
The alphabets are Z, U. So z + 5 = e (circularly), u + 5 = z.
The program must accept a string S as the input. The
program must print the largest number present in the string
as the output.
Example Input/Output 1:
Input: hello23welcome76
Output: 76
Example Input/Output 2:
Input: 9good8morning4
Output: 9
Alternate Rows Triangle Pattern
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
Output Format:
The pattern is printed as shown in the Example Input/Output
section.
Example Input/Output 1:
Input:
4
Output:
---1
--3-2
-4-5-6
10-9-8-7
Example Input/Output 2:
Input:
5
Output:
----1
---3-2
--4-5-6
-10-9-8-7
11-12-13-14-15
An integer matrix of size RxC is passed as the input to the
program. The program must print the sum of elements which are
not present in the border of the matrix.
Output Format: The first line contains the sum of elements which
are not present along the border.
Example Input/Output 1:
Input: 4 4
18 5 5 21
23 24 1 25
8 5 15 17
23 4 29 2
Output: 45
Example Input/Output 2:
Input: 5 6
93 60 84 26 22 95
99 96 86 90 34 0
0 83 63 10 74 75
36 35 98 4 22 18
20 8 27 94 64 30
Output: 695
Alternate X Characters
Boundary Condition(s):
2 <= Length of String, S <= 1000
2 <= X <= 10
Input Format:
The first line contains the string S.
The second line contains the value of X.
Output Format:
The first line contains the string with alternate X characters.
Example Input/Output 1:
Input:
helloworld
3
Output:
helorl
Example Input/Output 2:
Input:
environmentalpollution
5
Output:
envirtalpoon
Array Adjacent Sum M Times
An array of N integers and an integer value M are given as input. The program
must calculate the sum of adjacent elements for each element for M times.
Boundary Condition(s):
2 <= N <= 1000
1 <= M <= 100
Input Format:
The first line contains N and M separated by space(s).
The second line contains N integers separated by space(s).
Output Format:
The first line contains N integers separated by a space.
Example Input/Output 1:
Input:
32
259
Output:
11 10 11
Explanation:
pass 1-> 5 11 5
pass 2-> 11 10 11
Example Input/Output 2:
Input:
53
12 13 10 8 3
Output:
34 57 63 48 29
Explanation
pass 1-> 13 22 21 13 8
pass 2-> 22 34 35 29 13
pass 3-> 34 57 63 48 29
An integer N is passed as the input to the program. The
program must print the next prime number of N as the
output. That is the smallest prime number which is greater
than N.
Example Input/Output 1:
Input: 8
Output: 11
Example Input/Output 2:
Input: 29
Output: 31
The program must accept two integers X and Y as the input.
The program must print their sum S if the number of digits in S
is equal to X. Else the program must print the integer X as the
output.
Example Input/Output 1:
Input: 4 997
Output: 1001
Example Input/Output 2:
Input: 8 3
Output: 8
Array Adjacent Sum M Times
Boundary Condition(s):
2 <= N <= 1000
1 <= M <= 100
Input Format:
The first line contains N and M separated by space(s).
The second line contains N integers separated by space(s).
Output Format:
The first line contains N integers separated by a space.
Example Input/Output 1:
Input:
32
259
Output:
11 10 11
Explanation:
pass 1-> 5 11 5
pass 2-> 11 10 11
Example Input/Output 2:
Input:
53
12 13 10 8 3
Output:
34 57 63 48 29
'''
The program must accept N integers and an integer X as the
input. For each integer, the program must square the value of
the integer and then add X to it. Then the program must print
all the integers except the integers which are ending with 5 or
6. If the modified values of all the N integers are ending with 5
or 6 then the program must print -1 as the output.
Example Input/Output 1:
Input: 4 10
3147
Output: 19 11 59
Example Input/Output 2:
Input: 4 2
2 18 22 8
Output: -1
Array Print Every Mth Integer
Boundary Condition(s):
1 <= N <= 100000
Input Format:
The first line contains N and M separated by space(s).
The second line contains N integers separated by space(s).
Output Format:
The first line contains every Mth integer values separated
by a space.
Example Input/Output 1:
Input:
72
1234567
Output:
246
Example Input/Output 2:
Input:
10 3
22 72 94 29 19 27 392 28 20 67
Output:
94 27 20
The program must accept an integer N as the input. The
program must print the desired pattern as shown in the
Example Input/Output section.
Example Input/Output 1:
Input: 2
Output: *()*
(())
*()*
Example Input/Output 2:
Input: 5
Output: ****()****
***(())***
**((()))**
*(((())))*
((((()))))
*(((())))*
**((()))**
***(())***
****()****
Bar Graph Pattern
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
The second line contains N integers separated by space.
Output Format:
The pattern is printed as shown in the Example Input/Output
section.
Example Input/Output 1:
Input:
3
213
Output:
--*
*-*
***
Example Input/Output 2:
Input:
6
632421
Output:
*-----
*-----
*--*--
**-*--
*****-
******
The program must accept an integer N as the input. The
program must print the sum of the first N terms in the series
given below. The order of the series must be 1, -2, 3, -4, 5, -6 and
so on (All the odd terms in the series formed from the positive
odd numbers and all the even terms in the series formed from
the negative even numbers).
Example Input/Output 1:
Input: 5
Output: 3
Example Input/Output 2:
Input: 8
Output: -4
The program must accept an integer N as the input. The program
must print valid if N is a prime number or an even number. Else
the program must print invalid as the output.
Example Input/Output 1:
Input: 53
Output: valid
Example Input/Output 2:
Input: 100
Output: valid
Example Input/Output 3:
Input: 27
Output: invalid
Bomb Blast Survivors
An N*N grid is passed as input to the program. There are bombs planted in the
grid. Each bomb is detonated and destroys all the blocks in its explosion radius (If
the radius is 1, the bomb can destroy all the 8 blocks surrounding it). There are
people inside the grid represented by P. The bombs are represented by an
integer which is the explosion radius of the bombs. The program must print the
number of survivors after the explosion of all bombs.
Boundary Condition(s):
1 <= N <= 100
1 <= Explosion radius <= 9
Input Format:
The first line contains N
The next N lines contain N characters each.
Output Format:
The first line contains the count of survivors.
Example Input/Output 1:
Input:
6
**P***
****P*
*P*1**
*****P
***P*P
***PP2
Output:
2
The program must accept two integers X and Y as the input.
The program must print all the integers from X to Y which do
not have continuously repeated digits that is the digits are
repeated and all the digits in the number are same.
Example Input/Output 1:
Input: 5 15
Output: 5 6 7 8 9 10 12 13 14 15
Example Input/Output 2:
Input: 1 50
Output: 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 23 24
25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46
47 48 49 50
The program must accept the value of a string S as the
input. The program must reverse all the words in S except
the first and the last word of the string. Then the program
must print the modified string value as the output.
Example Input/Output 1:
Example Input/Output 2:
Input: I am fine
Output: I ma fine
Border Center Asterisk Pattern
Accept an integer N as the input. The program must print the pattern as
shown in the Example Input/Output section below. (Note:Integer N is
always odd). Asterisk is printed along the border and in the center of
the N*N matrix which is printed as the output.
Boundary Condition(s):
1 <= N <= 25
Input Format:
The first line contains the value of N.
Output Format:
The N lines contain the desired pattern.
Example Input/Output 1:
Input:
5
Ouput:
*****
*123*
*4*6*
*789*
*****
Example Input/Output 2:
Input:
3
Output:
***
***
***
Character Asterisk Alternate Pattern
An integer N is passed as the input. The program must print the pattern as
given in the Example Input/Output Section.
Boundary Condition(s):
2 <= N <= 100
Input Format:
The first line contains N.
Output Format:
The first N lines contain the pattern.
Example Input/Output 1:
Input:
3
Output:
a*b*c
*d*e*
f*g*h
Example Input/Output 2:
Input:
4
Output:
a*b*c*d
*e*f*g*
h*i*j*k
*l*m*n*
The program must accept two integers N and X as the
input. The program must reverse the last X digits in N. Then
the program must print the modified value of N as the
output.
Example Input/Output 1:
Input: 12345
3
Output: 12543
Example Input/Output 2:
Input: 6745424
4
Output: 6744245
Character Between Two Vowels
Input Format:
The first line contains the value of string S.
Output Format:
The first line contains the characters which are surrounded by vowels
on both sides if not print -1.
Boundary Condition:
3 <= length of the S <= 100
Example Input/Output 1:
Input:
acceleration
Output:
lrt
Example Input/Output 2:
Input:
knowledge
Output:
-1
Characters at Multiples of N Circularly
A string S and an integer N are given as input. The program must print
the characters present at the positions of multiples of N.
If the multiple of N goes beyond the last character, then the string
characters must be navigated in a cyclic manner till all the characters are
printed.
Each time when a character is printed, the printed character is slashed
and removed from the string.
Boundary Condition(s):
1 <= N, Length of string <= 1000
Input Format:
The first line contains S and N separated by space(s).
Output Format:
The first line contains the characters at positions of multiples of N.
Example Input/Output 1:
Input:
apple 2
Output:
plaep
Example Input/Output 2:
Input:
everything 4
Output:
rivhegnety
The program must accept a string S and an integer K as the
input. The program must reverse the middle K characters
in S. Then the program must print the modified string as
the output. Note: The length of S and the integer K are
always either odd or even.
Example Input/Output 1:
Input: acknowledgement
7
Output: acknegdelwoment
Example Input/Output 2:
Input: bottle
4
Output: blttoe
The program must accept a string value S as the input. The
program must print the desired pattern as shown in the
Example Input/Output section.
Example Input/Output 1:
Input: happy
Output: h
pa
*yp
Example Input/Output 2:
Input: orange
Output: o
ar
egn
Given a string s as the input with two or more words in it,
the program must reverse the order of the words in s.
Then the program must reverse each word in the even
positions. The resulting words in the modified order must
be printed as the output.
Input format: the first line contains the string with two or
more words separated by space(s).
Output format: the first line contains the reversed string
with words in the even position reversed.
Example input/output 1:
Input/output 2:
A matrix of size N*N is passed as input. The program must print yes if
there is at least one column in the matrix is a palindrome. Else the
program must print no.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
The next N lines contain N elements each separated by space(s).
Output Format:
The first line contains "yes" or "no".
Example Input/Output 1:
Input:
3
45 23 67
98 13 67
67 25 84
Output:
no
Example Input/Output 2:
Input:
4
34 56 14 93
76 93 76 20
86 93 16 30
34 56 14 93
The program must accept a string S and an integer N as the input. The program
must print the desired pattern as shown in the Example Input/Output section.
Output Format: The list of lines containing the desired pattern as shown in the
Example Input/Output section.
Example Input/Output 1:
Input: abcdefghijk
3
Output: a
*b
**c
*d
e
*f
**g
*h
i
*j
**k
Example Input/Output 2:
Input: accelerate
8
Output: a
*c
**c
***e
****l
*****e
******r
*******a
******t
*****e
Check Step Sequence
Boundary Condition(s):
1 <= N <= 9999
Input Format:
The first line contains N.
The second line contains N Integers separated by space(s).
Output Format:
The first line contains "yes" or "no".
Example Input/Output 1:
Input:
5
23432
Output:
yes
Example Input/Output 2:
Input:
6
567987
Output:
no
The program must accept a string S as the input. The
program must print the alphabets of S in reversal
alphabetical order as the output.
Example Input/Output 1:
Input: orange
Output: rongea
Example Input/Output 2:
Input: sweet
Ouput: wtsee
Circular Substring
Boundary Condition(s):
2 <= Length of String <= 1000
Input Format:
The first line contains S, start position and end position separated by
space(s).
Output Format:
The first line contains the substring.
Example Input/Output 1:
Input:
important 2 4
Output:
por
Example Input/Output 2:
Input:
think 3 1
Output:
nkth
The program must accept an integer X followed by the brand
name or the product number of N laptops with their costs. The
program must print either the brand name or the product
number of a laptop which has the minimum cost among N
laptops. If X is 1 then X is followed by the brand name. If X is 2
then X is followed by the product number. Fill in the missing
lines of code so that the program runs successfully. Note: If two
or more laptops have the same cost then print the information
of first occurring laptop. Input Format: The first line contains
the value of N. The next N lines contain an integer, a string
(brand name) or an integer (product number) and an integer
(cost) separated by space(s). Output Format: The first line
contains either a string (brand name) or an integer (product
number) of the laptop which has the minimum cost among N
laptops.
Example Input/Output 1:
Input: 4
1 Sony 70000
2 89793456 30000
2 65765767 60000
1 HP 45000
Output: 89793456
Example Input/Output 2:
Input: 3
1 Samsung 50000
2 76576777 45000
1 Acer 20000
Output: Acer
Circular Track to Reach Initial Position
Boundary Condition(s):
1 <= N <= 1000
1 <= I <= N
1 <= M <= 1000
Input Format:
The first line contains the value of N, I and M.
Output Format:
The first line contains the number of moves.
Example Input/Output 1:
Input:
10 2 5
Output:
2
Explanation:
2->7->2
Example Input/Output 2:
Input:
70 15 12
Output:
35
The program must accept an integer N and a digit D as the
input. The program must print the sum of the integers from 1 to
N which have the unit digit as D as the output. If there is no
such integer from 1 to N then the program must print -1 as the
output.
Example Input/Output 1:
Input: 30 3
Output: 39
Example Input/Output 2:
Input: 5 7
Output: -1
The program must accept an integer matrix of size rxc as the
input. the program must print the sum of top left quadrant
elements as the output.
Input format: the first line contains the integer values r and c
separated by space(s).
the next r lines contain c integers each separated by
space.
Output format: the first line contains the sum of top left
quadrant elements.
Example input/output 1:
Input: 4 4
1234
5678
9123
4567
Output: 14
Common Alphabets N Strings
N string values are passed as input to the program. Each string will contain only
the alphabets a-z in lower case. A given alphabet may be repeated any number of
times. The program must print the count C of the alphabets that are present in all
the N string values.
Input Format:
The first line contains N.
Next N lines contain the N string values.
Output Format:
The first line contains C.
Boundary Conditions:
2 <= N <= 500
1 <= Length of the string value <= 1000
Example Input/Output 1:
Input:
3
mnppqqr
ajkmnnm
poormanagement
Output:
2
Explanation:
Only 2 alphabets m and n are present in all the three string values.
Input:
5
ptkogphdtykhbgvqmykw
pnmcbtqodtdqjaeyayyp
yfvepcwyqyonglozltjo
nxfhvacwpvtxsrtvhwpt
dsaadnwrdpaqbalybvge
Expected Output:
1
Consecutive Characters from Two Strings
Two strings S1 and S2 are given as the input. If two alphabets from the string S2
occur consecutively in string S1, the second alphabet must be removed from
string S1. The program must print the string S1 after removing such occurrences.
Boundary Condition(s):
1 <= Length of S1 <= 1000
1 <= Length of S2 <= 26
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The first line contains a string.
Example Input/Output 1:
Input:
technology
echgy
Output:
tenolog
Explanation:
Two characters ec from s2 consecutively occur in technology. So the second
alphabet c is removed and technology becomes tehnology.
Two characters eh from s2 consecutively occur in tehnology. So the second
alphabet h is removed and tehnology becomes tenology.
Two characters gy from s2 consecutively occur in tenology. So the second
alphabet y is removed and tenology becomes tenolog.
Example Input/Output 2:
Input:
imagination
ahtng
Output:
imainion
1 An array of N integers is passed as the input to the program.
The program must print the sum of all the elements present
to the left of each element as the output.
Input: 5
2 4 6 8 10
Output: 0 2 6 12 20
Output Format: The first line contains either the sum of middle
four integers or the sum of middle three integers among N
integers.
Example Input/Output 1:
Input: 5
23576
Output: 15
Example Input/Output 2:
Input: 6
23 47 63 52 77 56
Output: 239
The program must accept an integer N as the input. The
program must print the desired pattern as shown in the
Example Input/Output sections.
Example Input/Output 1:
Input: 5
Output: 0
505
45054
3450543
234505432
12345054321
Example Input/Output 2:
Input: 4
Output: 0
404
34043
2340432
123404321
The program must accept a string S as the input. The
program must toggle the case of vowels in the string S. Then
the program must print the modified string as the output.
Example Input/Output 1:
Input: EquilIbriUm
Output: eqUIlibrIum
Example Input/Output 2:
Input: JUNKVIRUS
Output: JuNKViRuS
The program must accept an integer N as the input. The
program must print the desired pattern as shown in the
Example Input/Output section.
Example Input/Output 1:
Input: 43785
Output: 4
33
777
8888
55555
Example Input/Output 2:
Input: 10001
Output: 1
00
000
0000
11111
An N*N matrix containing 1s and 0s is given as the input to the
program. The program must print the number of 2x2 unit
matrices in the given matrix. A matrix is said to be unit matrix if
all the integers are 1. Also, consider the overlapping matrices.
Example Input/Output 1:
Input: 3
101
111
110
Output: 1
Example Input/Output 2:
Input: 4
1011
1111
1100
0000
Output: 2
The program must a string S as the input. The program must
print all the vowels in the string followed by all the
consonants in the string as the output.
Example input/output 1:
Input: elephant
Output: eealphnt
Example input/output 2:
Input: HETEROGENEOUS
Output: EEOEEOUHTRGNS
The program must accept an integer N as the input. The
program must print the pattern as shown in the Example
Input/Output sections.
Example Input/Output 1:
Input: 15
Output: ***************
**-----------**
*-*---------*-*
*--*-------*--*
*---*-----*---*
*----*---*----*
*-----*-*-----*
*------*------*
*-----*-*-----*
*----*---*----*
*---*-----*---*
*--*-------*--*
*-*---------*-*
**-----------**
***************
Rook Game
Two players A and B are playing a game. In that game, there is a chessboard of size R*C, where
they take turns placing the rooks. The cells with the rook are represented by 1. The empty cells
are represented by 0. In each turn, a player must place a rook.
When a player is unable to make a move, he loses and the game ends. The initial state of the
chessboard is passed as the input to the program. The program must print the winner of the
game if player A starts the game.
Note: Both the players have an infinite number of rooks to play the game.
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C integers separated by a space.
Output Format:
The first line contains A or B.
Example Input/Output 1:
Input:
33
100
000
100
Output:
A
Example Input/Output 2:
Input:
32
11
01
10
Output:
B
Example Input/Output 3:
Input:
22
00
00
Output:
B
Emptying Water from Buckets
There are N buckets arranged in a row. Each bucket has a certain amount of water. The
maximum capacity and the amount of water in each bucket are passed as the input. A boy
performs N-1 operations based on the following conditions.
- In the first operation, he empties the 1st bucket into the 2nd bucket (i.e., pouring water from
the 1st bucket into the 2nd bucket).
- In the second operation, he empties the 2nd bucket into the 3rd bucket.
- Similarly, he performs the remaining operations.
- During the emptying operation, if the next bucket is full and some water is remaining in the
current bucket, the water will be kept in the same bucket.
After N-1 operations, the program must print the amount of water in the last bucket and the
total amount of water remaining in the first N-1 buckets.
Input Format:
The first line contains N.
The second line contains N integers separated by a space representing the maximum
capacities of the N buckets.
The third line contains N integers separated by a space representing the amount of water in the
N buckets.
Output Format:
The first line contains two integers separated by a space representing the amount of water in
the last bucket and the total amount of water remaining in the first N-1 buckets.
Example Input/Output 1:
Input:
3
345
134
Output:
53
Example Input/Output 2:
Input:
3
323
000
Output:
00
Example Input/Output 3:
Input:
4
10 20 30 40
2222
Output:
80
function countDivisibleByThree
The function/method countDivisibleByThree accepts an argument str
representing a string value. The string str contains only digits and it represents an
integer.
Boundary Condition(s):
1 <= Length of the given string <= 100
Example Input/Output 1:
Input:
23
Output:
7
Explanation:
The 7 possible ways are given below.
03, 21, 24, 27, 33, 63 and 93.
Example Input/Output 2:
Input:
100
Output:
10
Example Input/Output 3:
Input:
28041587931619954605240353727
Output:
69
function countDivisibleByThree
The function/method countDivisibleByThree accepts an argument
str representing a string value. The string str contains only digits
and it represents an integer.
Boundary Condition(s):
1 <= Length of the given string <= 100
Example Input/Output 1:
Input:
23
Output:
7
Example Input/Output 2:
Input:
100
Output:
10
Example Input/Output 3:
Input:
28041587931619954605240353727
Output:
69
Replace Color - Adjacent Pixels
The program must accept a character matrix of size R*C representing an image, the
location of a pixel in the image (X, Y) and a color CH as the input. The program must replace
the color of the given pixel and all adjacent same colored pixels with the color CH (all 8
possible directions). Finally, the program must print the revised matrix as the output.
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C characters separated by a space.
The R+2nd contains X, Y and CH separated by a space.
Output Format:
The first R lines contain the revised matrix.
Example Input/Output 1:
Input:
43
BBW
WWW
WWW
BBB
22G
Output:
BBG
GGG
GGG
BBB
Example Input/Output 2:
Input:
56
RGRYYY
GRGYRR
RRRYRR
GRGYYY
GRRRGG
42P
Output:
PGPYYY
GPGYRR
PPPYRR
GPGYYY
GPPPGG
Assign Question Paper to Student
A class teacher has 26 sets of question papers named from A to Z. He
wants to conduct a test for his class students. Each student has a
registration number. He assigns a question paper to each student based
on the following condition.
- Find the sum of all the digits in the registration number. If the sum is
within the range 1-26, then the corresponding question paper set is
assigned to the student. Else the sum of the digits is calculated again and
again til the sum falls within the range 1-26, and then the corresponding
question paper set is assigned to the student.
The program must accept an integer R representing the registration
number of a student as the input. The program must print the name of the
question paper set assigned to the student as the output.
Boundary Condition(s):
1 <= R <= 10^9
Input Format:
The first line contains R.
Output Format:
The first line contains an alphabet representing the name of the question
paper set assigned to the student.
Example Input/Output 1:
Input:
100954
Output:
S
Example Input/Output 2:
Input:
9223399
Output:
J
Substring & Repeated String
The program must accept two string values S1 and S2 as the input. The
program must print YES if S1 can be formed when S2 is repeated any number
of times. Else the program must print NO as the output.
Boundary Condition(s):
1 <= Length of S2 <= Length of S1 <= 100
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The first line contains either YES or NO.
Example Input/Output 1:
Input:
antantan
ant
Output:
YES
Example Input/Output 2:
Input:
bookbookbook
ookb
Output:
YES
Example Input/Output 3:
Input:
SkillRack
llRackSkl
Output:
NO
Power of 2 Matrix
The program must accept an integer N as the input. The program must form an
integer matrix of size (2^N)*(2^N). The program must fill the matrix with the
integers submatrix by submatrix of size 2*2 in the order (Top-left, Top-right, Bottom-
left and Bottom-right) as shown in the Example Input/Output section.
Boundary Condition(s):
1 <= N <= 7
Input Format:
The first line contains N.
Output Format:
The first 2^N lines contain the integer matrix as shown in the Example Input/Output
section.
Example Input/Output 1:
Input:
3
Output:
1 2 5 6 17 18 21 22
3 4 7 8 19 20 23 24
9 10 13 14 25 26 29 30
11 12 15 16 27 28 31 32
33 34 37 38 49 50 53 54
35 36 39 40 51 52 55 56
41 42 45 46 57 58 61 62
43 44 47 48 59 60 63 64
Example Input/Output 2:
Input:
2
Output:
1256
3478
9 10 13 14
11 12 15 16
Example Input/Output 3:
Input:
1
Output:
12
34
Validate Variable Name
The program must accept a string S representing a variable name as the input. The
program must validate the given variable name based on the following conditions.
- Only English letters, digits and underscore are allowed.
- The variable name must not start with digits.
The program must print YES if the given variable name is valid. Else the program must
print NO as the output.
Boundary Condition(s):
1 <= Length of S <= 50
Input Format:
The first line contains S.
Output Format:
The first line contains YES or NO.
Example Input/Output 1:
Input:
Max_1_count
Output:
YES
Example Input/Output 2:
Input:
2_min
Output:
NO
Example Input/Output 3:
Input:
onesCount#1
Output:
NO
Example Input/Output 4:
Input:
max Value
Output:
NO
function findMaximum
The function/method findMaximum accepts four arguments R, C, matrix and K. The first two arguments R and C
represent the size of an integer matrix. The third argument represents the R*C integer matrix. The fourth
argument represents an integer value.
The function/method findMaximum must form an integer matrix of size M*N, where M = R/K and N = C/K. Then
the function must fill the matrix with the maximum value in each K*K submatrix of the given matrix. Finally, the
function must return the M*N matrix.
Your task is to implement the function findMaximum so that it passes all the test cases.
The following structure is used to represent the boundedArray and is already defined in the default code (Do not
write this definition again in your code).
typedef struct BoundedArray
{
int M, N;
int **matrix;
} boundedArray;
Example Input/Output 1:
Input:
99
18 38 31 65 47 68 96 49 31
30 23 83 78 38 19 24 94 43
24 17 49 21 94 84 86 53 78
43 67 64 42 68 13 95 85 64
27 54 69 76 43 37 92 19 26
61 58 84 85 83 36 11 17 15
20 24 50 74 58 17 40 20 90
82 31 24 88 78 68 67 24 72
69 24 87 41 32 68 37 79 80
3
Output:
83 94 96
84 85 95
87 88 90
Example Input/Output 2:
Input:
68
26 13 27 55 35 51 78 24
72 83 25 80 34 10 60 17
14 36 38 77 67 47 41 15
61 69 42 82 63 86 43 56
66 22 19 53 87 12 57 50
81 49 46 44 23 90 62 11
2
Output:
83 80 51 78
69 82 86 56
81 53 90 62
Sum - Digits on Left and Right
The program must accept an integer N containing only nonzero
digits as the input. For each digit D in the integer N, the program
must form an integer by concatenating D digits on the left and
D digits on the right of the D. Then the program must print the
sum of the resulting integer values. If the number of digits on
the left or right is less than D, then consider only the existing
digits on the left or right.
Boundary Condition(s):
10 <= N <= 10^8
Input Format:
The first line contains N.
Output Format:
The first line contains an integer value representing the sum of
resulting integer values.
Example Input/Output 1:
Input:
2314
Output:
510
Example Input/Output 2:
Input:
541326
Output:
201089
Print between Repeated Characters
The program must accept a string S as the input. The program must print the characters between
the repeated characters(inclusive) as the output. If there are no repeating characters, then the
program must print -1 as the output.
Boundary Condition(s):
2 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The lines contain the characters between the repeated characters(inclusive) or -1 as the output.
Example Input/Output 1:
Input:
skillrack
Output:
killrack
ll
Example Input/Output 2:
Input:
qualification
Output:
alifica
ifi
icati
Example Input/Output 3:
Input:
svghakjufr
Output:
-1
Example Input/Output 4:
Input:
bbaabbaabb
Output:
bb
baab
bb
baab
bb
aa
abba
Sorted List with Duplicates
Hector forms a list of integers that contains only positive integers in ascending order. The
program must accept N integers representing the integers to be inserted or removed in the list.
Initially, the list is empty. For each integer X among the N integers, the program must insert the
integer X into the sorted list if X is positive. Otherwise, the program must remove one
occurrence of the absolute value of X from the list(if exists). After each insert/remove
operation, the program must print the integers in the list. If there is no integer in the list, then
the program must print EMPTY as the output.
Input Format:
The first line contains N.
The second line contains N integer values separated by a space.
Output Format:
The first N lines, each contains integer values separated by a space or the string value EMPTY.
Example Input/Output 1:
Input:
11
10 30 10 20 10 20 10 -10 -40 20 -30
Output:
10
10 30
10 10 30
10 10 20 30
10 10 10 20 30
10 10 10 20 20 30
10 10 10 10 20 20 30
10 10 10 20 20 30
10 10 10 20 20 30
10 10 10 20 20 20 30
10 10 10 20 20 20
Example Input/Output 2:
Input:
8
-50 35 25 15 -25 -15 -35 50
Output:
EMPTY
35
25 35
15 25 35
15 35
35
EMPTY
50
Count the 1s in the binary representation
A positive integer N is passed as the input. The program
must print the number of 1s in the binary representation of
N.
Input Format:
First line contains N.
Output Format:
First line contains the count of 1s in the binary
representation of N.
Boundary Conditions:
1 <= N <= 9000000000000000000
Example Input/Output 1:
Input:
22
Output:
3
function incrementRowWise
The function/method incrementRowWise accepts three arguments R, C
and matrix. The integers R and C represent the size of the integer matrix.
Example Input/Output 1:
Input:
33
123
456
789
Output:
234
678
10 11 12
Example Input/Output 2:
Input:
45
10 20 30 40 50
8 18 28 38 48
55 44 33 22 11
6 7 8 9 10
Output:
11 21 31 41 51
10 20 30 40 50
58 47 36 25 14
10 11 12 13 14
Isomorphic Strings
Given two strings S1 and S2, the program must print if they are
isomorphic or [Link] strings are isomorphic if the characters in
S1 can be replaced to get S2 based on the conditions given below.
- All occurrences of a character must be replaced with another
character while preserving the order of characters.
- No two characters can map to the same character but a
character can map to itself.
Input Format:
The first line contains S1
The second line contains S2
Output Format:
The first line contains YES or NO indicating if S1 and S2 are
isomorphic or not.
Boundary Conditions:
1 <= Length of S1 and S2 <= 1000
Example Input/Output 1:
Input:
fill
bell
Output:
YES
Example Input/Output 2:
Input:
paper
title
Output:
YES
Example Input/Output 3:
Input:
pen
egg
Output:
NO
Max Execution Time Limit: 5000 millisecsA
Count Binary Value in Matrix
Accept an integer matrix with size RxC and N as input, the matrix contains only 0's and 1's. The
program must print the count of the binary value of N present in the matrix (row-wise and
column-wise).
Boundary Condition(s):
1 <= R, C <= 49
1 <= N <= 100
Input Format:
The first line contains the integer value of R and C separated by space.
The next R lines contain C integers each separated by space.
The R+2th line contains the integer value of N.
Output Format:
The first line contains the count of the binary value of N present in the matrix (row-wise and
column-wise).
Example Input/Output 1:
Input:
45
10101
00000
11111
10100
5
Output:
6
Example Input/Output 2:
Input:
55
10010
01011
00100
10000
01000
4
Output:
9
Electronic Display - Maximum Value
In a four-digit electronic display, each digit is displayed using seven segments. The
program must accept an integer N representing the number of segments to display an
integer X. The program must print the maximum possible four-digit integer X that can be
displayed using N segments as the output.
The number of segments required to display each digit is given below.
0-6
1-2
2-5
3-5
4-4
5-5
6-6
7-3
8-7
9-6
Boundary Condition(s):
8 <= N <= 28
Input Format:
The first line contains N.
Output Format:
The first line contains X.
Example Input/Output 1:
Input:
13
Output:
9711
Example Input/Output 2:
Input:
10
Output:
7711
Example Input/Output 3:
Input:
18
Output:
9977
Count of Uppercase Letters
Boundary Condition(s):
1 <= length of string <= 1000
Input Format:
The first line contains the string.
Output Format:
Example Input/Output 1:
Input:
aPpLe
Output:
2
Example Input/Output 2:
Input:
MoNGoDB
Output:
5
Split Sum - Floating Point Values
The program must accept N floating point values as the input. The program
must divide the given N floating point values into the following two
categories.
1) The floating point values are greater than X.5, where X is the integer part of
a floating point value.
2) The floating point values are less than or equal to X.5, where X is the integer
part of a floating point value.
Finally, the program must print the sum of the integer parts of the floating
point values in both categories separated by a space as the output.
Boundary Condition(s):
1 <= N <= 100
1.00000 <= Each floating point value <= 99999.99999
Input Format:
The first line contains N.
The second line contains N floating point values separated by a space.
Output Format:
The first line contains two integers separated by a space representing the two
sum values based on the given conditions.
Example Input/Output 1:
Input:
5
100.50001 12.5 10.45 9.501 20.49999
Output:
109 42
Example Input/Output 2:
Input:
6
1.5 2.1 3.0 10.6 10.99 5.51
Output:
25 6
Define class Travels
A travel company receives N booking requests. Each booking request contains the source city, the
destination city and the number of persons. Each bus in the travels has a maximum of X seats. The
program must accept the N booking requests and the value of X as the input. For each booking
request, the program must process the request and print the output based on the following
conditions.
- If the number of seats remaining in the bus (from the given source to the given destination) is
greater than or equal to the number of persons in the booking request, then the seats must be
booked and the program must print "Booked Successfully".
- Else the program must print "Failed" as the output.
Your task is to define the class Travels so that the program runs successfully.
N, X = map(int, input().split())
travels = Travels(X)
for ctr in range(N):
src, dest, count = input().strip().split()
print("Booked Successfully" if [Link](src, dest, int(count)) else "Failed")
Example Input/Output 1:
Input:
10 5
Trichy Coimbatore 10
Chennai Bangalore 2
Bangalore Chennai 5
Chennai Bangalore 3
Coimbatore Trichy 4
Trichy Coimbatore 1
Bangalore Chennai 1
Chennai Bangalore 4
Trichy Coimbatore 5
Trichy Coimbatore 2
Output:
Failed
Booked Successfully
Booked Successfully
Booked Successfully
Booked Successfully
Booked Successfully
Failed
Failed
Failed
Booked Successfully
Example Input/Output 2:
Input:
9 15
Bangalore Dindigul 8
Madurai Salem 11
Bangalore Dindigul 15
Hosur Bangalore 10
Hosur Bangalore 3
Theni Coimbatore 12
Hosur Bangalore 4
Theni Hosur 18
Trichy Theni 1
Output:
Booked Successfully
Booked Successfully
Failed
Booked Successfully
Booked Successfully
Booked Successfully
Failed
Failed
Booked Successfully
Crop Water Calculator
A farmer wants to plant paddy crops in his farm. So he visited a near by agriculture
shop to buy seeds. The shopkeeper showed the farmer various varieties of paddy
seed. Each variety of paddy seed varies from one another especially on the
Number of Days D needed to water and it's Growth Rate G. The quantity of water in
certain units required by a single crop in a single day is same as the growth rate on
that particular day. The Growth Rate G reduces by a value R everyday which will
reduce the water consumption by crops. The shopkeeper issued S number of seeds
to the farmer and assuming all seeds will grow, write a program to find the units of
Water Consumption W for D days.
Input Format:
The first line contains the value of Number of Seeds S, Growth Rate G, Number of
Days D to grow and the Reduction in Growth Rate R each separated by a space.
Output Format:
The first line contains the total units of Water Consumption W in D days.
Boundary Conditions:
1 <= S, G, D, R <= 999999
Example Input/Output 1:
Input:
10 5 5 1
Output:
150
Explanation:
The total number of seeds S the farmer will buy is 10.
The number of days D the crop has to be watered is 5
The growth rate G of each seed is 5.
The growth rate G is reduced by R-value 1 on every day. So, for the day 1 G is 5, day
2 G is 4, day 3 it is 3 and so on.
The Water Consumption W for 5 days = 10*5 + 10*4 + 10*3 + 10*2 + 10*1 = 150 units
Example Input/Output 2:
Input:
100 10 10 0
Output:
10000
Decreasing Sequence with Difference Decreasing
Boundary Condition(s):
2 <= N <= 9999999
1 <= D <= 9999999
Input Format:
The first line contains N and D separated by space(s).
Output Format:
The first line contains integers separated by a space.
Example Input/Output 1:
Input:
20 5
Output:
15 11 8 6 5
Example Input/Output 2:
Input:
12 6
Output:
6 1 -3 -6 -8 -9
Insert between Characters
The program must accept a string S (which does not contain any
space) and another character CH. The program must insert the
character CH between every adjacent pairs of characters in the string
S.
Boundary Condition(s):
1 <= Length of S <= 100
Input Format:
The first line contains S.
The second line contains CH.
Output Format:
The first line contains a string value.
Example Input/Output 1:
Input:
abcde
:
Output:
[Link].
Example Input/Output 2:
Input:
k
Output:
k
Example Input/Output 3:
Input:
on
-
Output:
o-n
Deliver from Farm to Shops
Note: The distance from the farm to a shop is calculated by the number
of cities it has to cross to reach the shop.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
The next lines contain the name of the two locations (source and
destination) connected by a road separated by space(s).
Output Format:
The first line contains the name of the shops separated by a space.
Example Input/Output 1:
Input:
5
farm mid1
mid1 mid2
mid2 shop1
mid2 mid3
mid3 shop2
Output:
shop1 shop2
Matrix Sum - L or Inverted L
The program must accept an integer matrix of size N*N as the input. The program
must find the sum of integers in the L-shape and inverted L-shape of the matrix. If
the sum of the integers in L-shape and the sum of the integers in inverted L-shape
are equal then print YES as the output. Else the program must print NO as the
output.
Input Format:
The first line contains N.
The next N lines each contain N integers separated by a space.
Output Format:
The first line contains either YES or NO.
Example Input/Output 1:
Input:
4
1634
2342
3455
4567
Output:
YES
Example Input/Output 2:
Input:
5
7 27 20 60 67
82 77 12 74 32
98 14 62 1 77
45 11 55 6 92
27 30 30 27 8
Output:
NO
Example Input/Output 3:
Input:
7
5484262
2971123
1327233
2386798
6451421
8293213
7425437
Output:
YES
String with Three Integers
The program must accept two nonzero digits D1, D2 and a string S as the input. The program
must form three integers A, B and C based on the following conditions.
A = D1
B = (A*10)+D2
C = (B*10)+D2
The program must print Yes if the given string S is formed by the concatenation of integers
A, B and C (in any order and any number of times). Else the program must print No as the
output.
Note:
- The values of D1 and D2 are always not equal.
- The string S always contains nonzero digits.
Input Format:
The first line contains D1 and D2 separated by a space.
The second line contains S.
Output Format:
The first line contains Yes or No.
Example Input/Output 1:
Input:
13
11313313
Output:
Yes
Example Input/Output 2:
Input:
52
25222
Output:
No
Example Input/Output 3:
Input:
69
696969677
Output:
No
Pattern Printing - 005
Given an integer N as the input, the program must print 2N lines pattern output as described in the
Example Input/Output given below.
Input Format:
The first line contains N.
Output Format:
2N lines of the pattern.
Example Input/Output 1:
Input:
4
Output:
1
22
333
4444
4444
333
22
1
Example Input/Output2:
Input:
10
Output:
1
22
333
4444
55555
666666
7777777
88888888
999999999
10101010101010101010
10101010101010101010
999999999
88888888
7777777
666666
55555
4444
333
22
1
Given an input String S, accept the input string S and print the string
as shown in the Example Input/ Output section.
Input Format:
The first line contains the value of the string S. S may contain
alphabets, numbers and special characters.
Output Format:
The strings are printed in the Digital 7-Shaped format.
Boundary Conditions:
1 < Length of S <1000
xyz
Output:
xxx
yyx
zyx
Output:
111111
222221
333321
444321
554321
654321
Sanath rsean's encryption quest!
One day sean's friend john wanted him to encrypt a few messages that were to be sent via a
telegram group, so that everyone could see the message, but
only those special people who knew decryption can actually understand it. help sean write a code
that take input values of the type of encryption, a key, and a message to be encrypted that had
something to do with the [Link] format:first line containing the type of encryption [Link] line
containing the
key [Link] line containing the message m.
output format:
the first line contains the encrypted message.
Note:
The encryption process is based on the simple logic of addition, that is simply adding the value of
the key(/modified key) to the characters of the message to be encrypted. only upper case
alphabets need to be considered.x is a number -1 or 0 or 1,\
a) -1 denotes the decreasing value of the key
b) 0 denotes the constant value of the key
c) 1 denotes the increasing value of the keyd) in case of invalid input value of x simply display
“invalid input”.
if the input value of k is less than or equal to 0, make the initial value of k as 1
Boundary conditions:
The maximum length of the message m is 200 and it's minimum length is 1
output:
uxqrky
Boundary Condition(s):
1 <= N, Length of each rod <= 1000
Input Format:
The first line contains N.
The second line contains N integers separated by a space representing the length of N
rods.
Output Format:
The lines contain the integer values based on the given conditions.
Example Input/Output 1:
Input:
6
842278
Output:
6
4
3
2
Example Input/Output 2:
Input:
9
123454321
Output:
9
7
5
3
1
Divisible By Both 2 and 3
Boundary Condition(s):
1 <= N <= 10000
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the integers divisible by both 2 and 3
separated by a space.
Example Input/Output 1:
Input:
5
8 6 12 9 24
Output:
6 12 24
Example Input/Output 2:
Input:
7
22 24 67 60 93 96 102
Output:
24 60 96 102
function areConsecutive
The function/method areConsecutive accepts an argument str. The
string str contains only [Link] function/method areConsecutive must
return 1 if the given string represents the concatenation of two
consecutive integers. Else the function must return [Link] task is to
implement the function areConsecutive so that the program runs
successfully.
Example Input/Output 1:
Input:
256257
Output:
1
Example Input/Output 2:
Input:
4241
Output:
1
Example
Input/Output 3:
Input:
99100
Output:
1
Example Input/Output 4:
Input:
20412024
Output:
0
Dynamic V Pattern
The program must accept two integers (X, Y) and a character CH as the input. The
program must print the desired pattern as shown in the
Example Input/Output section.
Boundary Condition(s):
1 <= X, Y <= 1000
Input Format:
The first line contains the values of X, CH and Y separated by a space.
Output Format:
The list of lines containing the desired pattern as shown in the Example Input/Output
section.
Example Input/Output 1:
Input:
3#5
Output:
------#
-----#
#---#
-#-#
--#
Example Input/Output 2:
Input:
7@7
Output:
@-----------@
-@---------@
--@-------@
---@-----@
----@---@
-----@-@
------@
Example Input/Output 3:
Input:
10 * 4
Output:
*
-*
--*
---*
----*
-----*
------*-----*
-------*---*
--------*-*
---------*
Equidistant Characters from Start & End
Given a string value S1 the program must print only the characters
which are present in the same position from the start of S1 as well as
the end of S1 in the order of their occurrence.
Boundary Condition(s):
1 <= Length of S1 <= 1000
Input Format:
The first line contains S1.
Output Format:
The first line contains the string value containing the characters
which are present in the same position from the start of S1 as well as
the end of S1.
Example Input/Output 1:
Input:
engine
Output:
en
Example Input/Output 2:
Input:
malayalam
Output:
malay
Maximum Sum - No Adjacent
The program must accept an integer matrix of size 2*N as the input. The program
must print the maximum sum such that no two chosen integers are adjacent
vertically, diagonally or horizontally in the matrix.
Boundary Condition(s):
2 <= N <= 100
1 <= Matrix element value <= 10^5
Input Format:
The first line contains N.
The next two lines, each contains N integer values separated by a space.
Output Format:
The first line contains the maximum sum.
Example Input/Output 1:
Input:
3
256
311
Output:
9
Example Input/Output 2:
Input:
5
13578
2 4 6 8 10
Output:
18
Example Input/Output 3:
Input:
4
9873
7649
Output:
18
Unique Alphabets to Ranges
The program must accept a string S containing only lower case
alphabets as the input. The program must find the unique
alphabets in the given string and print the alphabets as ranges in
sorted order as shown in the Example Input/Output section.
Boundary Condition(s):
1 <= Length of S <= 100
Input Format:
The first line contains S.
Output Format:
The lines contain the alphabets ranges in sorted order.
Example Input/Output 1:
Input:
fhjgipqrtsifif
Output:
f:j
p:t
Example Input/Output 2:
Input:
abbackxxyzzponm
Output:
a:c
k:k
m:p
x:z
Special Number
An integer N is a special number if N can be expressed as a sum
of an integer X and its reverse. The program must print if N is a
special number or not.
Boundary Condition(s):
1 <= N <= 10^6
Input Format:
The first line contains N.
Output Format:
The first line contains true or false.
Example Input/Output 1:
Input:
22
Output:
true
Example Input/Output 2:
Input:
121
Output:
true
Example Input/Output 3:
Input:
15
Output:
false
Escape Speed
Example Input/Output 1:
Input:
1.567 2.4783 3.4671
Output:
1.497
Example Input/Output 2:
Input:
1.9038 2.7920 4.3937
Output:
1.555
function sortSubstrings
The function/method sortSubstrings accepts two arguments str and K.
The str represents a string value whose length is always divisible by the
integer K.
Example Input/Output 1:
Input:
skillrack
3
Output:
ack llr ski
Example Input/Output 2:
Input:
internationalairport
4
Output:
inte iona lair port rnat
Evaluation of Simple Expression
Boundary Condition(s):
1 <= Length of the string <= 1000
Input Format:
The first line contains the expression.
Output Format:
The first line contains the value of the expression.
Example Input/Output 1:
Input:
2^2+3*4-2
Output:
26
Example Input/Output 2:
Input:
4+23-100
Output:
-73
Prime Sentence
The program must accept a string S representing a sentence as the input. The program must
find the sentence value of S based on the following conditions.
- All 26 alphabets from a to z or from A to Z have values are from 1 to 26 respectively.
- All 10 digits from 0 to 9 have values are from 0 to 9 respectively.
- All the other characters have the value 0.
- The sentence value is obtained by summing up all the numeric values of every single
character in S.
Then the program must print the output based on the following conditions.
- If the sentence value is a prime number, then the program must print "Prime".
- If the sentence value is a prime number after removing exactly one word in the sentence,
then the program must print "Almost Prime".
- Otherwise, the program must print "Composite".
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains a string value based on the given conditions.
Example Input/Output 1:
Input:
Lift dog
Output:
Prime
Example Input/Output 2:
Input:
Is 24 the answer?
Output:
Almost Prime
Example Input/Output 3:
Input:
Hello World!
Output:
Composite
Find and Replace
The program must accept three string values S1, S2 and S3 as the
input. The program must find all occurrences of the string S1 in the
string S3 and replace all the occurrences of the string S1 by the string
S2. Finally, the program must print the modified string S3 as the
output.
Note: String values are only in lower case
Hint: Use strcmp() in-built function
Boundary Condition(s):
1 <= Length of S1, S2 <= 20
1 <= Length of S3 <= 1000
Example Input/Output 1:
Input:
tiger lion
the tiger is a wild animal the tiger is known as the king of the jungle
Output:
the lion is a wild animal the lion is known as the king of the jungle
Example Input/Output 2:
Input:
abcd xyz
bcd abc abcd cde abcde abcd asdf bcde
Output:
bcd abc xyz cde abcde xyz asdf bcde
function findBinarySum
The function/method findBinarySum accepts two arguments N and
binValues. The binValues represents a 2-D array of characters denoting
the N binary string values.
Boundary Condition(s):
2 <= N <= 100
1 <= Length of each string <= 100
Example Input/Output 1:
Input:
2
10001
11001
Output:
101010
Example Input/Output 2:
Input:
3
1000
111
100010
Output:
110001
Find the Closest Palindrome
The program must accept a number N as the input. The program must print
the closest palindromic number as the output. If there are two closest
palindromic numbers the program must print the smaller number.
Boundary Condition(s):
2 <= N <= 99999999999999
Input Format:
The first line contains the value of N.
Output Format:
The first line contains the closest palindromic number.
Example Input/Output 1:
Input:
124
Output:
121
Example Input/Output 2:
Input:
1439
Output:
1441
Input:
723891738
Expected Output:
723888327
Input:
12345678876543
Expected Output:
12345677654321
Cycle Tour
Hector has planned a cycle tour through the mountains. His tour consists of N checkpoints,
numbered from 1 to N in the order he will visit them. The ith checkpoint has a height of Hi.
A checkpoint is a peak if it is not the 1st checkpoint or the Nth checkpoint, and the height of the
checkpoint is strictly greater than the checkpoint immediately before it and the checkpoint
immediately after it.
Please help Hector find out the number of peaks.
The program must accept T test cases, where each test case contains N integers representing the
heights of the N checkpoints. For each test case, the program must print the number of peaks in
his cycle tour.
Input Format:
The first line contains T, followed by T test cases.
Each test case contains the input as below.
- The first line contains N.
- The second line contains N integers separated by a space.
Output Format:
The first T lines, each contains an integer representing the number of peaks in Hector's cycle tour.
Example Input/Output 1:
Input:
4
3
10 20 15
4
8888
5
20 80 30 80 20
3
100 30 100
Output:
1
0
2
0
Example Input/Output 2:
Input:
10
10
66 61 60 87 34 52 40 41 100 32
8
79 37 61 71 4 95 36 33
4
13 14 74 96
3
71 75 92
3
80 20 6
10
66 21 42 88 6 96 23 14 36 41
8
27 91 64 78 71 49 100 59
5
85 78 6 53 49
7
71 67 73 3 27 97 49
9
34 24 71 83 28 16 74 29 18
Output:
3
2
0
0
0
2
3
1
2
2
First Half and Second Half - String
The program must accept a string S as the input. The program must
print the alphabets of the string S which are in the first half of the
alphabets (a to m) and then the program must print the alphabets in
the string S which are in the second half of the alphabet (n to z) as the
output.
Note: The alphabets are only in lower case.
Boundary Condition(s):
1 <= Length of S <= 100
Example Input/Output 1:
Input:
electronics
Output:
elecictrons
Explantion:
The first half of the alphabets are e l e c i c
The second half of the alphabets are t r o n s
Hence the output is elecictrons
Example Input/Output 2:
Input:
keyboard
Output:
kebadyor
Print Directions - Visited Cities
The program must accept a matrix of size R*C representing R*C cities. A person
visits the cities from the top-left position and he marks the visited cities with
the integers starting from 1. The integers in the matrix represent the cities he
visited. The asterisks in the matrix represent the cities he has not visited. The
program must print the directions (N-North, S-South, E-East and W-West) in
which he visited the cities as the output.
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C values separated by a space.
Output Format:
The first line contains a list of characters separated by a space representing the
directions in which the person visited the cities.
Example Input/Output 1:
Input:
55
12*89
* 3 6 7 10
* 4 5 * 11
* * 16 * 12
* * 15 14 13
Output:
ESSENENESSSSWWN
Example Input/Output 2:
Input:
75
1*567
234*8
****9
20 * * 11 10
19 * 13 12 *
18 15 14 * *
17 16 * * *
Output:
SEENEESSSWSWSWSWNNN
First and Last Odd Digits
Boundary Condition(s):
1 <= N <= 9999
Input Format:
The first line contains N.
The second line contains N integers separated by space.
Output Format:
The first line contains the specified output.
Example Input/Output 1:
Input:
4
21 33 12 15
Output:
33 15
Example Input/Output 2:
Input:
7
123 456 567 21 58 93 103
Output:
123 567 93 103
function reverseStringRetainCase
The function/method reverseStringRetainCase accepts an
argument str representing a string value that contains
multiple words.
Example Input/Output 1:
Input:
Chennai TamilNadu
Output:
Iannehc UdanlImat
Example Input/Output 2:
Input:
GoogleChrome FireFox MicrosoftEdge
Output:
EmorhcElgoog XofeRif EgdetfosoRcim
Form Greater Number by Swapping
Boundary Condition(s):
2 <= Number of digits in N <= 100
Input Format:
The first line contains N.
The second line contains M.
The third line contains M integers separated by space(s).
Output Format:
The first line contains an integer with its digits swapped.
Example Input/Output 1:
Input:
2343214
2
25
Output:
3243214
Example Input/Output 2:
Input:
902374890234
3
3 6 10
Output:
920378492034
Example Input/Output 2:
Input:
699731787022457192428222653599464501803523986
13
1 2 4 5 7 8 9 10 11 20 25 44 45
Employees - Working Time
The program must accept the name, in-time and out-time (in 24-hr format HH:MM) of N employees as the
input. The program must print the names of the employees in descending order based on their working time.
If two or more employees have the same working time then those employees must be printed in
chronological order based on their in-time. If two or more employees have the same working time and the
same in-time then those employees must be printed in sorted order based on their names.
Input Format:
The first line contains N.
The next N lines, each contains the name, in-time and out-time of an employee separated by a space.
Output Format:
The first N lines contain the names of the N employees based on the given conditions.
Example Input/Output 1:
Input:
7
Rajesh 08:45 16:45
Catherine 09:15 17:45
Deepa 08:00 18:00
Pravin 09:00 17:30
Jhanvi 08:45 16:45
Hector 09:00 18:00
Mambo 09:00 17:00
Output:
Deepa
Hector
Pravin
Catherine
Jhanvi
Rajesh
Mambo
Example Input/Output 2:
Input:
6
Bhuvana 16:00 23:00
Anu 11:00 23:00
Hector 09:30 16:30
John 10:15 20:15
Ramesh 09:30 16:29
Anita 09:30 16:30
Output:
Anu
John
Anita
Hector
Bhuvana
Ramesh
File - Reverse Lines
The program must accept a string S denoting the name of a text file and an integer N
as the input. The program must read the first N lines from the given file. Then the
program must print the N lines in reverse order as the output.
Note: The given file is always present in the same folder where the program executes.
Boundary Condition(s):
5 <= Length of S <= 20
1 <= N <= Number of lines in the file <= 100
1 <= Length of each line in the file <= 100
Input Format:
The first line contains S.
The second line contains N.
Output Format:
The first N lines contain the first N lines of the given file in reverse order.
Example Input/Output 1:
Input:
[Link]
5
Output:
rose
red
the
pluck
You
Example Input/Output 2:
Input:
[Link]
2
Output:
Dog
Lion
Frequency of Alphabets in Descending Order
The program must accept a string S with lower case alphabets and print
the alphabets in the descending order of frequency of their occurrence. If
more than one alphabets are repeated for the same number of times, then
the program must print them in alphabetical order.
Boundary Condition(s):
1 <= Length of String S <= 150
Input Format:
The first line contains the string S.
Output Format:
The first line contains the alphabets sorted based on their frequency.
Example Input/Output 1:
Input:
apple
Output:
pael
Explanation:
In apple, the frequency of occurrence is a-1, p-2, l-1, e-1
So p comes first followed by a e l (thats in alphabetical order).
Example Input/Output 2:
Input:
czechoslovakia
Ouput:
acoehiklsvz
String - Shift Consonants
The program must accept a string S containing only alphabets
as the input. The program must shift the consonants to the
left by 1 position in the string S. Then the program must print
the revised string as the output.
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the revised string S.
Example Input/Output 1:
Input:
Gujarat
Output:
jurataG
Example Input/Output 2:
Input:
TooL
Output:
LooT
Gold Pots Unit Digit
A series of N gold pot is found by a man. He starts picking the gold coins from
the first pot. He moves forward by the unit digit value of the count of gold coins
in the current pot and picks up the next pot. This is continued until there are no
more pots at the unit digit position from the current pot. The number of gold
coins in each pot is given as input. The program must print the total gold coins
collected.
Boundary Condition(s):
2 <= N <= 1000
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the total number of gold coins collected.
Example Input/Output 1:
Input:
7
452 231 871 943 25 762 823
Output:
3089
Explanation:
Gold pots are collected in the following order 452, 871, 943 and 823.
Example Input/Output 2:
Input:
5
91 42 72 194 32
Output:
327
Matrix Layers - Repeated Sum
The program must accept an integer matrix of size N*N as the input. The program must find the
sum of integers in each layer of the matrix (from outer layer to inner layer). Then the program must
print the repeated sum among the obtained sum values. If two or more sum values are repeated,
then the program must print the first occurring sum as the output. If there is no repeated sum,
then the program must print -1 as the output.
Boundary Condition(s):
3 <= N <= 50
0 <= Matrix element value <= 1000
Input Format:
The first line contains N.
The next N lines each contain N integers separated by a space.
Output Format:
The first line contains an integer representing the repeated sum or -1 based on the given
conditions.
Example Input/Output 1:
Input:
5
23451
3 10 6 7 2
4 13 6 9 2
56533
75724
Output:
59
Example Input/Output 2:
Input:
7
76 56 96 69 12 75 81
76 69 64 95 57 62 53
84 32 64 24 18 51 10
99 8 64 22 12 88 23
52 94 28 93 43 95 97
40 1 91 8 56 84 50
76 65 20 87 97 45 80
Output:
-1
Example Input/Output 3:
Input:
8
11111111
12222221
11111121
11133121
11133111
11111111
11111111
11111111
Output:
28
Hundredth Digit Odd
Three numbers are passed as input. The program must print the number having
an odd digit in its hundredth place.
Boundary Condition(s):
1 <= N <= 999999999
Input Format:
The first line contains N.
Output Format:
The first line contains an integer.
Example Input/Output 1:
Input:
12345 400 3478
Output:
12345
Example Input/Output 2:
Input:
3439 849 567
Output:
567
Common Odd Digits - Same Position
The program must accept two integers X and Y as the input. The
program must print the integer formed by the common odd digits in
the same positions starting from the unit digit of X and Y as the
output.
Note: There will be at least one common odd digit in X and Y at the
same position.
Boundary Condition(s):
1 <= X, Y <= 10^8
Input Format:
The first line contains X.
The second line contains Y.
Output Format:
The first line contains an integer value based on the given conditions.
Example Input/Output 1:
Input:
1234599
31579
Output:
359
Example Input/Output 2:
Input:
12345
12435
Output:
15
Infinity Symbol Pattern
Given a matrix M of size N*N as input, the program must print the
output as shown in the Example Input/Output section.
Boundary Condition(s):
2 <= N <= 50
Input Format:
The first line contains the value of N.
The next N lines contain N values each separated by space.
Output Format:
The first line contains the desired output as shown in the Example
Input/Output section.
Example Input/Output 1:
Input:
3
123
567
234
Output:
164736251
Example Input/Output 2:
Input:
4
1234
5678
9 10 11 12
13 14 15 16
Output:
1 6 11 16 12 8 4 7 10 13 9 5 1
Python - C 008
Please convert the following python code to c so that the c
program executes successfully passing the test cases.
The function/method findMaxCost accepts two arguments N and boxes. The array 'boxes'
represents an array of type 'Box' and it contains N elements. Each element of boxes consists of
three positive integers 'pens', 'pencils' and 'erasers' representing the count of pens, pencils
and erasers in a box respectively. The cost of a pen, pencil and eraser are 10, 5 and 3
respectively.
The function/method findMaxCost must return an integer representing the maximum cost of a
box among the given N boxes.
Your task is to implement the function findMaxCost so that the program runs successfully.
Example Input/Output 1:
Input:
4
251
123
313
333
Output:
54
Example Input/Output 2:
Input:
2
10 1 1
5 10 10
Output:
130
Integers Occurring Odd Number of Times
The program must accept an integer array of size N as the input. The
program must print the integers that are occurring odd number of
times in the array as the output. If there is no integer occurring odd
number of times, then the program must print -1 as the output.
Boundary Condition(s):
3 <= N <= 100
1 <= Each integer < 100
Example Input/Output 1:
Input:
5
23345
Output:
245
Example Input/Output 2:
Input:
4
21 11 21 11
Output:
-1
Interlace Odd Even Matrix Pattern
The program must accept an integer N as the input. The program must print an integer
matrix of size N*N containing with the odd and even integers alternately among the integers
from 1 to N*N as shown in the Example Input/Output section.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
Output Format:
The first N lines, each contains N integers separated by a space representing the N*N
matrix.
Example Input/Output 1:
Input:
3
Output:
183
654
729
Example Input/Output 2:
Input:
4
Output:
1 16 3 14
5 12 7 10
9 8 11 6
13 4 15 2
Example Input/Output 3:
Input:
5
Output:
1 24 3 22 5
20 7 18 9 16
11 14 13 12 15
10 17 8 19 6
21 4 23 2 25
Interchange Diagonals in Matrix
Boundary Condition(s):
1 <= N <= 50
Input Format:
The first line contains the value of N.
The next N lines contain N integers each separated by
space(s).
Output Format:
The first N lines contain N integers each separated by a
space.
Example Input/Output 1:
Input:
3
516
429
873
Output:
615
429
378
Camel Case Pattern Matching
The program must accept two string values S and P as the input. The string P represents a
pattern and the string S represents a string to be matched with the pattern P. The program
must print YES if the string S matches the pattern P. Else the program must print NO as the
output. The string S matches the pattern P if and only if we can insert lower case alphabets
in P so that it is equal to the string S.
Boundary Condition(s):
1 <= Length of S, P <= 1000
Input Format:
The first line contains S.
The second line contains P.
Output Format:
The first line contains either YES or NO.
Example Input/Output 1:
Input:
FootBall
FoBa
Output:
YES
Example Input/Output 2:
Input:
GreedyAlgorithm
GAl
Output:
YES
Example Input/Output 3:
Input:
MondayToTuesday
MoTo
Output:
NO
Example Input/Output 4:
Input:
NorthEastSouth
NooES
Output:
NO
Integer Compression - Right to Left
The program must accept an integer N as the input. The program must
compress the integer by concatenating the sum of every two digits from right
to left in N until the integer becomes a single-digit integer. The program must
print the integer values obtained during the compression process(including N)
as the output.
Boundary Condition(s):
0 <= N <= 10^8
Input Format:
The first line contains N.
Output Format:
The lines contain the integer values based on the given conditions.
Example Input/Output 1:
Input:
2345677
Output:
2345677
271114
925
97
16
7
Example Input/Output 2:
Input:
1234566
Output:
1234566
15912
1143
27
9
Inverted V Pattern
The program must accept the values of string S1 and S2 as input. The program must print the
desired pattern as shown in the Example Input/Output section.
Boundary Condition(s):
2 <= Length of S1, S2 <= 100
Input Format:
The first line contains the value of string S1.
The second line contains the value of string S2.
Output Format:
The list of lines contain the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
orange
energy
Output:
-----e
----g-n
---n---e
--a-----r
-r-------g
o---------y
Example Input/Output 2:
Input:
apple
orange
Output:
-1
Example Input/Output 3:
Input:
neuro
lemon
Output:
----n
---o-e
--m---u
-e-----r
l-------o
function getConsecutiveVowels
The function/method getConsecutiveVowels accepts an argument str representing a
string value which contains only alphabets.
Your task is to implement the function getConsecutiveVowels so that it passes all the test
cases.
The following structure is used to represent the boundedArray and is already defined in
the default code (Do not write this definition again in your code).
typedef struct BoundedArray
{
int SIZE;
char **vowels;
} boundedArray;
Example Input/Output 1:
Input:
eagle
Output:
ea
e
Example Input/Output 2:
Input:
AbcdEIOfghIOUA
Output:
A
EIO
IOUA
Example Input/Output 3:
Input:
jklmn
Output:
-1
IPv4 Address Validity
Boundary Condition(s):
1 <= Length of address <= 50
Input Format:
The first line contains the IP address.
Output Format:
The first line contains Valid or Invalid.
Example Input/Output 1:
Input:
[Link]
Output:
Valid
Example Input/Output 2:
Input:
[Link].12
Output:
Invalid
Append Alphabet - Surrounding Integers
The program must accept a matrix of size R*C containing integers and alphabets as the input.
For each occurrence of the alphabet in the matrix, the program must append
the alphabet to the surrounding integers of the alphabet. Then the program must print the
revised matrix as the output.
Note: In the given matrix, there are no common integers around two or more alphabets.
Boundary Condition(s):
2 <= R, C <= 50
1 <= Each integer value in the matrix <= 1000
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C elements of the matrix separated by a space.
Output Format:
The first R lines contain the revised matrix.
Example Input/Output 1:
Input:
45
52224
7523b
8a559
93856
Output:
5 2 2 2b 4b
7a 5a 2a 3b b8
a a 5a 5b 9b
9a 3a 8a 5 6
Example Input/Output 2:
Input:
55
86 77 45 57 82
13 A 10 86 70
32 74 72 27 C
28 79 12 43 90
15 B 13 15 37
Output:
86A 77A 45A 57 82
13A A 10A 86C 70C
32A 74A 72A 27C C
28B 79B 12B 43C 90C
15B B 13B 15 37
Largest Even Number
The program must accept two numbers N1 and N2 as the input and it
must print the largest possible even number with non-zero unit digit
as the output containing all the digits from both the numbers. If an
even number with non-zero unit digit cannot be formed using the
digits from the two numbers, the program must print -1 as the
output.
Note: The last digit must not be zero.
Boundary Condition(s):
1 <= N1, N2 <= 99999999
Input Format:
The first line contains the value of N1 and N2 separated by space.
Output Format:
The first line contains the largest possible even number.
Example Input/Output 1:
Input:
784201 86976
Output:
98877664102
Digits Asterisks Pattern
The program must accept a string S containing only digits as the input. The program must
print the digits in the string S based on the following conditions.
- The digits of the same value must be printed on the same line.
- The values of the digits must be printed in the order of their occurrence.
- The empty spaces in each row must be printed as asterisks.
Input Format:
The first line contains S.
Output Format:
The lines contain the digits and asterisks based on the given conditions.
Example Input/Output 1:
Input:
1225644789964
Output:
1**
22*
5**
66*
444
7**
8**
99*
Example:
Here S = 1225644789964.
1 occurs one time.
2 occurs two times.
5 occurs one time.
6 occurs two times.
4 occurs three times.
7 occurs one time.
8 occurs one time.
9 occurs two times.
Example Input/Output 2:
Input:
624655622653
Output:
6666
222*
4***
555*
3***
7
Largest Integer in Each Row
Given a matrix M of size R*C, the program must print the largest integer
in each row.
Boundary Condition(s):
2 < R, C < 50
Input Format:
The first line contains R and C separated by space.
The next R lines contain C values each separated by a space.
Output Format:
The first R lines contain the largest integer in each row.
Example Input/Output 1:
Input:
33
123
465
789
Output:
3
6
9
Example Input/Output 2:
Input:
34
12 23 34 45
21 3 55 67
2 45 56 12
Output:
45
67
56
Move to Beginning - Operations Count
The program must accept a string S and two integers X, Y as the input.
The program must perform the following two operations alternately on
the given string S until the string becomes the original string.
- Move the last X characters to the beginning.
- Move the last Y characters to the beginning.
Finally, the program must print the number of operations performed on
the given string S as the output.
Boundary Condition(s):
1 <= Length of S <= 100
1 <= X, Y <= Length of S
Input Format:
The first line contains S.
The second line contains X and Y separated by a space.
Output Format:
The first line contains an integer representing the number of operations
performed on the given string S.
Example Input/Output 1:
Input:
high
12
Output:
3
Example Input/Output 2:
Input:
SkillRack
31
Output:
13
function sortBasedOnDigits
The function/method sortBasedOnDigits accepts two arguments
SIZE and arr. The integer SIZE represents the size of the integer
array arr.
Example Input/Output 1:
Input:
6
200 2 22 32 3 4
Output:
2 200 22 3 32 4
Example Input/Output 2:
Input:
5
124 1201 204 230 104
Output:
104 1201 124 204 230
Largest Unit Digit Number
Boundary Condition(s):
1 <= X, Y <= 1000000
Input Format:
The first line contains X and Y separated by a space.
Output Format:
The first line contains an integer value.
Example Input/Output 1:
Input:
51 23
Output:
23
Example Input/Output 2:
Input:
77 87
Output:
87
Frequency Shift Encryption
The program must accept a string S containing only lower case
alphabets as the input. The program must encrypt the given string
based on the following conditions.
- For each alphabet CH in the string S, the program must modify the
alphabet based on a shift value.
- The value of the shift is determined by the count of occurrences of
CH before the position of CH in the original string S.
- If the modified value of the alphabet goes beyond 'z', the shift wraps
around to the beginning (i.e., If the alphabet is 'z' and the shift value is
2, then the modified value is 'b').
Finally, the program must print the encrypted string as the output.
Boundary Condition(s):
2 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the encrypted string.
Example Input/Output 1:
Input:
currentaffairs
Output:
cursentafgbits
Example Input/Output 2:
Input:
abyzabyzabyz
Output:
abyzbczacdab
Last Repeating Integer
N integers are passed as the input. The program must print the last
repeating integer among the N integers.
Boundary Condition(s):
1 <= N, value of integers <= 1000
Input Format:
The first line contains the integer N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the last repeating integer.
Example Input/Output 1:
Input:
6
121527
Output:
2
Example Input/Output 2:
Input:
7
12 34 34 34 12 45 67
Output:
12
Split Integers - Even Number of Digits
The program must accept an integer N as the input. The program must
split the integer into two equal halves if the number of digits in the integer
is even. Then the program must repeat the process on the resulting
integers till there is no integer with an even number of digits. The leading
zeroes must not be considered after each split operation. Finally, the
program must print the resulting integers in sorted order.
Boundary Condition(s):
1 <= N <= 10^18
Input Format:
The first line contains N.
Output Format:
The first line contains the integer values based on the given conditions.
Example Input/Output 1:
Input:
1024
Output:
0124
Example Input/Output 2:
Input:
50000006
Output:
0056
Example Input/Output 3:
Input:
923456
Output:
456 923
Train - Passengers Waiting Time
The program must accept the departure time of a train (in 24-hr format HH:MM) at a station S as
the input. The name and the arrival time (in 24-hr format HH:MM) of N persons to the station S are
also passed as the input to the program. The program must print the name of each person and
his/her waiting time (in minutes) at the station S as the output. If a person arrives at the station
after the train departs, then the program must print the name of the person followed by -1 as the
output.
Input Format:
The first line contains the departure of a train.
The second line contains N.
The next N lines, each contains the name of a person and the arrival time to the station separated
by a space.
Output Format:
The first N lines, each contains the name of a person followed by his/her waiting time at the
station S or -1 based on the given conditions.
Boundary Condition(s):
1 <= N <= 1000
Input Format:
The first line contains the series of integers separated by space(s).
Output Format:
The first line contains the least repeated digits in ascending order
separated by a space.
Example Input/Output 1:
Input:
35 81 78 84 53
Output:
147
Example Input/Output 2:
Input:
12 21 68 55 71 29 60 879
Output:
0
Shadow Sentences or Not
The program must accept two string values S1 and S2 representing two sentences as the
input. The program must print YES if the two sentences are shadows of each other. Else the
program must print NO as the output. If two sentences are shadows of each other, then the
following conditions must be true.
- The number of words in both sentences must be equal.
- The length of each word that occurs in the same position in both sentences must be equal,
but the corresponding words must not share any common characters.
Boundary Condition(s):
1 <= Length of S1, S2 <= 1000
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The first line contains YES or NO.
Example Input/Output 1:
Input:
four ten history
tent was damaged
Output:
YES
Example Input/Output 2:
Input:
hat mat tiger elephant
run gun water keyboard
Output:
NO
Example Input/Output 3:
Input:
mobile camera
army ant nano
Output:
NO
Left Right Odd Count
Boundary Condition(s):
1 <= N <= 10^5
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains N integers separated by a space.
Example Input/Output 1:
Input:
6
134857
Output:
-1 -1 4 8 -1 -1
Longest Continuous Alphabets Sequence
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains the string S.
Output Format:
The first line contains the longest continuous alphabets sequence in
the string.
Example Input/Output 1:
Input:
abchyzabs
Output:
yzab
Example Input/Output 2:
Input:
cdefghijklmnopqrst
Output:
cdefghijklmnopqrst
Longest Series Surrounded by M
Boundary Condition(s):
3 <= N <= 1000
1 <= M <= 999999999
Input Format:
The first line contains N and M separated by space(s).
The second line contains N integers separated by space(s).
Output Format:
The first line contains the longest series of integers separated by a
space.
Example Input/Output 1:
Input:
72
45 2 21 534 2 45 2
Output:
21 534
Example Input/Output 2:
Input:
10 23
23 76 23 129 34 12 23 45 67 23
Output:
129 34 12
Longest Substring Without Vowels
Boundary Condition(s):
2 <= Length of S <= 100
Input Format:
The first line contains the string S without any space.
Output Format:
The first line contains the longest substring without any vowels else
-1.
Example Input/Output 1:
Input:
awkxqdtpetsqwjh
Output:
wkxqdtp
Longest Word
The program must accept a string S as the input. The program print the
longest word from the string S as the output.
If two or more longest words are of same length then consider the first one.
Boundary Condition(s):
1 <= Length of S <= 1000
Example Input/Output 1:
Input:
Good Morning
Output:
Morning
Explanation:
The length of the word "Good" is 4 and the length of the "Morning" is 7
Hence Morning is printed as the output.
Example Input/Output 2:
Input:
good time
Output:
good
Lucky Draw Winner
Boundary Condition(s):
2 <= N <= 50
Input Format:
The first line contains the value of N.
The second line contain N values separated by space(s).
The third line contain N-1 values separated by space(s).
Output Format:
The first line contains the jersey number of the winner.
Example Input/Output 1:
Input:
6
100 200 300 400 500 600
14231
Output:
400
Matrix Non-Border Elements Sum
Boundary Condition(s):
2 <= R,C <= 50
Input Format:
The first line contains the value of R and C separated by space(s).
The next R lines contain C integers each separated by space.
Output Format:
The first line contains the sum of elements which are not present
along the border.
Example Input/Output 1:
Input:
44
18 5 5 21
23 24 1 25
8 5 15 17
23 4 29 2
Output:
45
Matrix Sort Corner Elements Clock-wise
An integer matrix of size R*C is passed as input. The program must sort the
elements at the corner position of the matrix in clock-wise direction and print
the matrix.
Boundary Condition(s):
1 <= R, C <= 1000
Input Format:
The first line contains the value of R and C separated by space(s).
The next R lines contain C elements each separated by space(s).
Output Format:
The first R lines contain C elements each separated by a space with corner
elements sorted in clock-wise direction.
Example Input/Output 1:
Input:
33
927
456
381
Output:
123
456
987
Example Input/Output 2:
Input:
43
924 450 994
58 146 589
526 548 407
471 145 779
Output:
471 450 779
58 146 589
526 548 407
994 145 924
Matrix Top View
A character matrix of size R*C is passed as input. The program must print the
first alphabet in each column.
Note: At least one alphabet will be present in a column.
Boundary Condition(s):
1 <= R <= 100
1 <= C <= 100
Input Format:
The first line contains the value of R and C.
Next lines contain the values in the R*C matrix with each value separated by
one space.
Output Format:
The first line contains the top view of the matrix.
Example Input/Output 1:
Input:
36
m--t-r
a-saed
iand-a
Output:
master
Example Input/Output 2:
Input:
49
s--l-r--k
-k--l-a--
--i------
-------c-
Output:
skillrack
Maximum of Odd and Even Digit Count
An integer N is passed as input. The program must print the odd digit
count if odd digit count is greater than even digit count. Else the
program must print the even digit count.
Boundary Condition(s):
1 <= N <= 999999999
Input Format:
The first line contains N.
Output Format:
The first line contains an integer.
Example Input/Output 1:
Input:
12345
Output:
3
Example Input/Output 2:
Input:
8982374
Output:
4
Minimum Spring Hops
A series of springs are represented as an array of size N. Each value in array defines the power of
spring to push the object forward. A starting spring value M is passed as input. Find the minimum
number of hops needed for the object to reach the last spring. If last spring cannot be reached
print -1.
Boundary Condition(s):
2 <= N <= 1000
1 <= M <= 1000
Input Format:
The first line contains the value of N and M separated by space(s).
The second line contains N integers separated by space(s).
Output Format:
The first line contains the minimum number of hops to reach the last spring.
Example Input/Output 1:
Input:
93
532113134
Output:
1
Explanation:
Starting value 3 occurs thrice. Traversing from 3 at 6th position will be minimal to reach the last
spring (3->4).
Example Input/Output 2:
Input:
10 5
5321837316
Output:
3
Explanation:
There is only one starting value 5. The number of hops needed is 3 (5->3->1->6).
Mirror Pattern Matrix
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
Output Format:
The first N lines contain the specified output.
Example Input/Output 1:
Input:
3
Output:
12321
45654
78987
Example Input/Output 2:
Input:
4
Output:
1234321
5678765
9 10 11 12 11 10 9
13 14 15 16 15 14 13
N Equal Strings
The program must accept a string S and an integer N as the input. The
program must print N equal parts of the string S if the string S can be
divided into N equal parts. Else the program must print -1 as the
output.
Boundary Condition(s):
2 <= Length of S <= 1000
2 <= N <= Length of S
Example Input/Output 1:
Input:
whiteblackgreen 3
Output:
white black green
Explanation:
Divide the string whiteblackgreen into 3 equal parts as white black
green
Hence the output is white black green
Example Input/Output 2:
Input:
pencilrubber 5
Output:
-1
N Integers Unit Digit Multiplication
Boundary Condition(s):
2 <= N <= 100
Input Format:
The first line contains the N.
The second line contains the N integers separated by space(s).
Output Format:
The first line contains the N integers.
Example Input/Output 1:
Input:
5
12 34 11 15 16
Output:
72 68 44 15 80
Example Input/Output 2:
Input:
3
123 145 16
Output:
738 435 80
Next Number Same Unit Digit
An array of N integers are given as input. The program must print the
integers only if the unit digit of the current integer and the unit digit
of the next integer are same.
Boundary Condition(s):
2 <= N <= 1000
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains integers separated by a space.
Example Input/Output 1:
Input:
6
12 834 94 485 285 905
Output:
834 485 285
Example Input/Output 2:
Input:
6
91 41 74 192 32 45
Output:
91 192
Next Palindromic Number
Boundary Condition(s):
1 <= N <= 999999999
Input Format:
The first line contains N.
Output Format:
The first line contains the immediate next palindromic
number of N.
Input:
119
Output:
121
Example Input/Output 2:
Input:
1111
Output:
1221
Nth Repeating Character - String
A string S is passed as the input to the program. The program must print
the Nth repeating character C in the string S. The repeating characters
are considered in their order of occurrence from the beginning of the
string S. If no such Nth repeating character is present the program must
print -1 as the output.
Input Format:
The first line contains the value of S.
Output Format:
The first line contains the value of C.
Boundary Conditions:
2 <= Length of S <= 1000
Example Input/Output 1:
Input:
abcdaeaedbapple
3
Output:
d
Example Input/Output 2:
Input:
desktoppublishing
3
Output:
i
Odd Border Elements
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains the value of N.
The next N lines contain the matrix.
Output Format:
The first line contains the odd integers present in the border of
the matrix each separated by a space.
Example Input/Output 1:
Input:
3
45 87 190
74 21 35
89 45 42
Output:
45 87 35 89 45
Example Input/Output 2:
Input:
4
56 78 12 30
90 56 27 29
65 278 25 9
37 81 77 20
Output:
29 65 9 37 81 77
First D Surrounding Digits SumThe program must accept an integer matrix of size
R*C containing only digits from 1 to 8 as the input.
For each digit D in the matrix, the program must print the sum of the first D
surrounding digits as the output.
If the number of surrounding digits of D is less than D, then the program must
print the sum of all the surrounding digits of D.
The order of surrounding digits is given below.
top-left, top, top-right, right, bottom-right, bottom, bottom-left and left.
Boundary Condition(s):
2 <= R, C <= 50
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C integers separated by a space.
Output Format:
The first R lines, each contains C integers separated by a space representing the
sum of surrounding digits based on the given conditions.
Example
Input/Output 1:
input:
33
752
383
241
Output:
16 23 11
20 27 8
11 15 8
Example Input/Output 2:
Input:
34
3443
1714
3552
Output:
12 13 15 9
3 25 4 14
13 17 19 5
Pattern Printing - Diamond Numbers
Input Format:
The first line contains N.
Output Format:
2N-1 lines containing the desired pattern.
Boundary Conditions:
2 <= N <= 50
Example Input/Output 1:
Input:
3
Output:
00100
02080
30007
04060
00500
Example Input/Output 2:
Input:
5
Output:
000010000
0 0 0 2 0 16 0 0 0
0 0 3 0 0 0 15 0 0
0 4 0 0 0 0 0 14 0
5 0 0 0 0 0 0 0 13
0 6 0 0 0 0 0 12 0
0 0 7 0 0 0 11 0 0
0 0 0 8 0 10 0 0 0
000090000
function getArrayFromString
The function/method getArrayFromString accepts two arguments str
and K representing a string value and an integer value respectively.
The string str contains only [Link] function/method
getArrayFromString must form K-digit integers from the given string
based on the following conditions.- For every K digits in the given
string, the function must form an integer.
If there are leading zeroes in the K digits, then the function must
move those leading zeroes to the end and form the [Link] the
function must return an array containing those K-digit integers.
Note:- The length of the string is always divisible by K.
- There will be at least one nonzero digit in every K digits.
Input: 121021562005468058 3
Output:121 210 562 500 468 580
Example Input/Output 2:
Input:50000004 4
Output:5000 4000
Random Number Game
In a game, there is a machine that generates a random number when a player presses
a button. Initially, a player puts X rupees in the machine and starts the game.
He can press the button N times. If he gets a random number equal to the amount in
the machine, then the amount gets doubled. After pressing the button N times, he
can collect the amount from the machine if the amount is doubled at least once.
Otherwise, he will lose the amount. The program must accept N integers representing
the N random numbers and the value of X as the input. The program must print the
final amount the player gets as the output.
Boundary Condition(s):
1 <= N <= 100
1 <= Each random number, X <= 10^6
Input Format:
Output Format:
The first line contains an integer representing the final amount the player gets.
Example Input/Output 1:
Input:
7
10 2 4 11 15 12 8
2
Output:
16
Example Input/Output 2:
Input:
6
15 20 50 4 6 10
5
Output:
0
In a straight line, a robot is placed at position 0 (i.e., at the time t=0, the robot is placed at 0).
The robot receives N moving commands. Each command contains two integers T and X, where
T represents the time in which the robot receives the command and X represents the
destination point on the straight line.
If the robot receives a command, it starts moving towards the destination point X with the
speed of 1 unit per second and it stops when it reaches the destination point. The robot
ignores the commands when it is moving.
The N commands are passed as the input to the program.
The program must print the number of commands ignored by the robot as the output.
Then the program must print the position of the robot after processing the N commands.
Note:
All commands are always given in chronological order based on the time T.
Input Format:
Output Format:
The first line contains an integer representing the number of commands ignored by the robot.
The second line contains an integer representing the final position of the robot.
Example
Input/Output 1:
Input:
3
15
24
61
Output:
1
1
Example Input/Output 2:
Input:6
1 -5
24
35
40
76
10 1
Output:
4
6
Pattern Printing - Mirror Image with Hyphens
Accept a number N as the input. The program must print the mirror image
pattern as the shown in the Example Input/Output section.
Boundary Condition(s):
3 <= N <= 30
Input Format:
The first line contains the value of N.
Output Format:
The first N lines contain the mirror image pattern.
Example Input/Output 1:
Input:
5
Output:
55555-55555
4444---4444
333-----333
22-------22
1---------1
Example Input/output 2:
Input:
4
Output:
4444-4444
333---333
22-----22
1-------1
Remove Unit Digits - Previous & Next
The program must accept a list of N integers and an integer T as the input.
The program must remove T unit digits in the given list of integers based on the
following conditions.
- The program must start removing the unit digits from the 1st integer.
- If the removed unit digit is even, then the program must remove the unit digit of
the next integer. Else the program must remove the unit digit of the previous
integer.
- Similarly, the program must remove T unit digits in the given list of integers.
- Once all the digits in an integer are removed, then the integer itself must be
removed from the given list.
- Consider the given list of integers in circular fashion when finding the previous
and next integers.
Finally, the program must print the sum S of the modified integers in the list as the
output.
If all integers are removed, then the program must print -1 as the output.
Input Format:
The first line contains N.
The second line contains N integers separated by a space.
The third line contains T.
Output Format:
Example Input/Output 1:
Input:
4
87369 4012 22312 39845
6
Output:
3903
Example Input/Output 2:
Input:
4
22 44 33 55
7
Output:
5
Example Input/Output 3:
Input:
3
123 456 789
9
Output:
-1
Pattern Printing - Start Number
Given an integer N as the input and a start integer S, print the pattern as given in the Example
Input/Output section.
Input Format:
The first line contains S and N, each separated by a space.
Output Format:
2N lines containing the desired pattern.
Boundary Conditions:
2 <= N <= 50
1 <= S <= 20
Example Input/Output 1:
Input:
34
Output:
3
44
555
6666
6666
555
44
3
Example Input/Output 2:
Input:
79
Output:
7
88
999
10 10 10 10
11 11 11 11 11
12 12 12 12 12 12
13 13 13 13 13 13 13
14 14 14 14 14 14 14 14
15 15 15 15 15 15 15 15 15
15 15 15 15 15 15 15 15 15
14 14 14 14 14 14 14 14
13 13 13 13 13 13 13
12 12 12 12 12 12
11 11 11 11 11
10 10 10 10
999
88
7
function removeReversedWords
Example
Input/Output 1:
Input:
nightingale lion tiger mosquito noil cockroach lion fox panda
lizard
lion
Output:
nightingale tiger mosquito cockroach fox panda lizard
Example
Input/Output 2:
Input:
monkey monkey yeknom monkey yeknom
yeknom
Output:
-1
Power of 2 or -2
Boundary Condition(s):
-10^17 <= N <= 10^17
Input Format:
The first line contains the value of N.
Output Format:
The first line contains either yes or no
Example Input/Output 1:
Input:
32
Output:
yes
Example Input/Output 2:
Input:
90
Output:
no
There are N empty buckets in a row. Every second, a certain number of balls fill
each bucket.
The maximum capacity of each bucket is K. If the number of balls exceeds the
maximum capacity of a bucket, the remaining balls will overflow.
When a bucket is full or overflowing, a boy collects the balls from the bucket and
empties the bucket again.
The program must accept an integer matrix of size T*N representing the number of
balls that fall into N buckets in T seconds and the value of K as the input.
The program must print the number of balls he can collect as the output.
At T = 1, the balls in the last row of the matrix will fall into the N buckets.
At T = 2, the balls in the last but one row of the matrix will fall into the N buckets
and so on.
Input Format:
Output Format:
The first line contains the number of balls the boy can collect.
Example Input/Output 1:
Input:
55
11514
54324
34322
51413
14222
8
Output:
48
Example
Input/Output 2:
Input:
67
4648625
7621168
2265618
4366779
5991713
9812752
22
Output:
154
String - Remove Minimum Characters
The program must accept a string S as the input. The program must print the minimum
number of characters to be removed from the string S so that the length of the revised
string must be even(possibly 0) also every two consecutive characters(non-overlapping)
must be different.
Boundary Condition(s):
2 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains an integer value representing the minimum number of characters to
be removed from S.
Example Input/Output 1:
Input:
coffee
Output:
2
Example Input/Output 2:
Input:
dddeeeeddd
Output:
6
Example Input/Output 3:
Input:
grapes
Output:
0
Example Input/Output 4:
Input:
aabbaaabbbc
Output:
3
Previous Number Same Unit Digit
An array of N integers are given as input. The program must print the
integers only if the unit digit of the current integer and unit digit of
the previous integer are same.
Boundary Condition(s):
2 <= N <= 1000
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains integers separated by a space.
Example Input/Output 1:
Input:
6
12 834 94 485 285 905
Output:
94 285 905
Example Input/Output 2:
Input:
6
91 41 74 192 32 45
Output:
41 32
First Non-Repeated Submatrix
The program must accept a character matrix of size R*C and an integer K as the input. The
values of R and C are always divisible by K. The program must print the first non-repeated
K*K submatrix in the given matrix as the output. If there is no such submatrix, then the
program must print -1 as the output.
Boundary Condition(s):
4 <= R, C <= 50
2 <= K <= 25
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C characters separated by a space.
The R+2nd line contains K.
Output Format:
The first K lines contain the first non-repeated K*K submatrix in the given matrix or the
first line contains -1.
Example
Input/Output 1:
Input:
69
abclmnabc
defpqrdef
ghixzyghi
cbacbanml
fedfedrqp
ihgihgyzx
3
Output:
lmn
pqr
xzy
Example
Input/Output 2:
Input:
44
abcd
efgh
cdab
ghef
2
Output:
-1
Collect Gold Coins - Instructions
In a room, the RxC boxes are arranged as a matrix where each box contains gold coins. A
set of instructions are given to a boy to pick the boxes in the room. The initial position of the
boy is (1, 1). He can move around the room based on the following instructions.
- If it is N, then he can move 1 step towards North.
- If it is E, then he can move 1 step towards East.
- If it is W, then he can move 1 step towards West.
- If it is S, then he can move 1 step towards South.
The boy is allowed to take gold coins from the room based on the following conditions.
- He must take all the coins out of the box when he picks a box the first time.
- Whenever he picks up the same box a second time or more, he must put 1 gold coin in
that box using the same gold coins that he collected from the same box. If there are no coins
to put in the box when picking it multiple times, then he just ignores the box.
The program must accept an integer matrix of size RxC representing the RxC boxes and a
string S representing the set of instructions as the input. The program must print the total
number of gold coins he can collect as the output.
Note:
The given instructions are always valid (i.e., there is no instruction that will take him out of
the room).
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C integers separated by a space.
The R+2nd line contains S.
Output Format:
The first line contains an integer representing the total number of gold coins he can collect.
Example Input/Output 1:
Input:
33
546
251
123
EESWNW
Output:
19
Example Input/Output 2:
Input:
33
546
251
123
EESWNESSNN
Output:20
Explanation:
Initially, he collects 5 gold coins from the box (1, 1).
E -> He collects 4 gold coins from the box (1, 2).
E -> He collects 6 gold coins from the box (1, 3).
S -> He collects 1 gold coin from the box (2, 3).
W -> He collects 5 gold coins from the box (2, 2).
N -> He puts 1 gold coin in the box (1, 2).
E -> He puts 1 gold coin in the box (1, 3).
S -> He puts 1 gold coin in the box (2, 3).
S -> He collects 3 gold coins from the box (3, 3).
N -> He just ignores the box (2, 3) as there are no coins to put in that box.
N -> He puts 1 gold coin in the box (1, 3).
The total gold coins = 5 + 4 + 6 + 1 + 5 - 1 - 1 - 1 + 3 + 0 - 1 = 20.
So 20 is printed as the output.
Print A To B, C To B And B To D
Given four integers A, B, C and D as input, the program must print the
numbers from A to B in the first line, C to B in the second line and B
to D in the third line.
Boundary Condition(s):
1 <= A, B, C, D <= 1000
Input Format:
The first line contains the values of A, B, C and D separated by
space(s).
Output Format:
The first line contains values from A to B separated by space.
The second line contains values from C to B separated by space.
The third line contains values from B to D separated by space.
Example Input/Output 1:
Input:
1234
Output:
12
32
234
Example Input/Output 2:
Input:
28 35 47 58
Output:
28 29 30 31 32 33 34 35
47 46 45 44 43 42 41 40 39 38 37 36 35
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
58
function removeRowsWithSameValue
The function/method removeRowsWithSameValue accepts three arguments - R, C and
matrix. The first two arguments R and C represent the size of an integer matrix. The third
argument matrix represents a pointer to the integer matrix.
The function/method removeRowsWithSameValue must remove the rows having the same
value. Then the function must return the revised matrix. If all the rows of the matrix are
removed, then the function must return a matrix of size 1*1 with the value -1.
Your task is to fill in the missing lines of code to implement the function
removeRowsWithSameValue so that it passes all the test cases.
The following structure is used to represent the boundedArray and is already defined in the
default code (Do not write this definition again in your code).
Example Input/Output 1:
Input:
54
10 20 30 10
50 50 50 50
55 55 66 55
40 30 20 10
55 55 55 55
Output:
10 20 30 10
55 55 66 55
40 30 20 10
Example Input/Output 2:
Input:
33
444
888
222
Output:
-1
Iron Rods - Strictly Increasing Order
There are N iron rods arranged in a row based on the height in ascending order. A boy cuts
the iron rods in strictly increasing order so that the absolute difference between the heights
of every two consecutive iron rods is 1. The boy never cuts the first iron rod. After cutting
the N-1 iron rods, he starts melting and making new iron rods with the remaining rods. The
boy wants to place as many new rods as possible to the right side of the N rods without
violating the strictly increasing order of height.
The program accepts N integers representing the heights of the N iron rods as the input. The
program must print the heights of the iron rods after cutting and making the new rods as the
output.
Boundary Condition(s):
2 <= N <= 100
1 <= Each integer value <= 10^5
Input Format:
The first line contains N.
The second line contains N integer values separated by a space representing the heights of
the N iron rods.
Output Format:
The first line contains the integer values separated by a space representing the heights of
the iron rods based on the given conditions.
Example Input/Output 1:
Input:
4
2 5 8 12
Output:
234567
Example Input/Output 2:
Input:
5
5 6 7 10 21
Output:
5 6 7 8 9 10
Example Input/Output 3:
Input:
7
18 19 20 21 22 23 24
Output:
18 19 20 21 22 23 24
Max Call Duration - Call Logs
The program must accept the outgoing call logs of a mobile number as the input. Each call
log contains the mobile number, call start time and end time. The program must print the
mobile number having the maximum call duration. If there are two or more such mobile
numbers having the maximum call duration, then the program must print them in the order
of their occurrence.
Boundary Condition(s):
2 <= N <= 50
Input Format:
The first line contains N.
The next N lines, each contains the mobile number, call start time and end time separated by
a space.
Output Format:
The lines contain the mobile number(s) having the maximum call duration.
Example Input/Output 1:
Input:
5
9876543210 [Link] [Link]
9998887775 [Link] [Link]
9876543210 [Link] [Link]
9998887775 [Link] [Link]
9998887775 [Link] [Link]
Output:
9876543210
Explanation:
9876543210 (2 times) -> Total duration: 92 + 255 = 347 seconds.
9998887775 (3 times) -> Total duration: 10 + 108 + 73 = 191 seconds.
The mobile number 9876543210 is having the maximum call duration.
Hence the output is 9876543210.
Example Input/Output 2:
Input:
6
9876543210 [Link] [Link]
9998887775 [Link] [Link]
9876543210 [Link] [Link]
9998887775 [Link] [Link]
9998887775 [Link] [Link]
9998887775 [Link] [Link]
Output:
9876543210
9998887775
Find Area - Radius or Diameter
The program must accept an integer Q as the input. If
the value of Q is 1, then the radius of a circle is passed
as the input. If the value of Q is 2, then the diameter of
a circle is passed as the input. The program must print
the area of the circle with the precision up to 2 decimal
places as the output.
Example Input/Output 1:
Input:
1
5
Output:
78.57
Example Input/Output 2:
Input:
2
7.5
Output:
44.20
function getTotalPrice
Example Input/Output 1:
Input:
Cost of 5 pens is 50.98 rupees. Cost of a pencil is 4.25.
Output:
55.23
Example Input/Output 2:
Input:
A is 5.60, B is 2.14, C is 100.58 and D is 50.6.
Output:
158.92
Boats & Ships - North or West
The program must accept a character matrix of size R*C representing a port as the
input. The character asterisk (*) represents water. The character hash symbol (#)
represents a boat. Two consecutive hash symbols (vertically or horizontally)
represent a ship. The vertical ships can move only towards the north. The
horizontal ships can move only towards the west. The boats can move towards
north or west. The boats and ships leave the port based on the following
conditions.
- Every odd minute, the first occurring boat or the vertical ship in each column
leave the port (towards north).
- Every even minute, the first occurring boat or the horizontal ship in each row
leave the port (towards west).
- A boat or ship cannot move if there is another boat or ship on its way.
The program must print the number of minutes it takes to empty the port as the
output.
Input Format:
The first line contains R and C separated by a space.
The next R lines, each contains C characters separated by a space.
Output Format:
The first line contains the number of minutes it takes to empty the port.
Example Input/Output 1:
Input:
76
##*##*
**#**#
#*#*#*
****#*
#*##*#
*#****
****#*
Output:
5
Example Input/Output 2:
Input:
67
***#*##
##*****
**#**#*
*#*#*#*
*#*#**#
#*#**#*
Output:
4
Multiply the Unit Digit in Reverse Order
The program must accept N integers as the input. The
program must multiply the unit digit of each integer
with
itself and print the product values in reverse order as
the output.
Input Format:
The first line contains N.
The second line contains N integers separated by
space.
Output Format:
The first line N integers separated by a space.
Example Input/Output l:
Input:
5
24 17 5 36 214
The program must accept two characters CHI, CH2, and an integer N as the input. The program
must print the desired
pattern as shown in the Example Input/Output section.
Boundary Condition(s):
Input Format:
The first line contains the values Of CHI, CH2 and N separated by space(s).
Output Format:
The first N lines containing the desired pattern as shown in the Example Input/Output section.
:
Input:
Output:
ACCCCCC
AACCCCC
AAACCCC
AAAACCC
AAAAAAC
AAAAAAA
Print Next Even Digit
Given a number N, the program must print the next even digit
for each of the digits in N,
Boundary Condition(s):
1 <= N <= 999999999
Input Format:
The first line contains N.
Output Format:
The first line contains the specified output.
Example Input/Output 1:
Input:
123
Output:
244
Example Input/Output 2:
Input:
789
Output:
800
Print the Floating Point Values
Boundary Condition(s):
3 <= Length of String S <= 49
Input Format:
The first line contains the string value S.
Output Format:
The list of lines contain all the float values in S.
Example Input/Output 1:
Input:
hello12.34madam45.67
Output:
12.34
45.67
The praogram must accept a str ing value S as the input.
The program must pc int the expanded string as shown in
the
Example Input/Output section.
gouruiary Condition(s):
1 Length of S 100
Inmlt Format:
The first line contains the values of string S.
Output Format:
The first line contains the expanded string as shown in
the Example section.
lncNJt/[Link] I:
Input:
orange
Output:
egengeangerangeorange
Explanation:
The string orange is expanded as e ge nge range (Mange.
Hence the output is egerweangeratWorar%e
Vxanwe 7:
Input:
Water
rerteraterWater
Rearrange Matrix without Duplicates in Each Column
Boundary Condition(s):
1 <= R, C <= 50
0 <= Matrix Element <= 999999
Input Format:
The first line contains the value of R and C separated by space(s).
The next R lines contain C integers separated by space(s).
Output Format:
The first line contains either "YES" or "NO".
Example Input/Output 1:
Input:
33
455
467
757
Output:
YES
Explanation:
The given matrix can be rearranged as
445
556
777
The program must accept an integer N and a digit D as the
input. The program must print the sum of the
integers from I to N which have the unit digit as D as the
output. If there is no such integer from I to N
then the program must print -1 as the output.
Boundary Condition(s):
1 1000
Input Format:
The first line contains the values of N and D seperated by
space
Output Format:
The first line contains either the sum of the integers from
1 to N which have the unit digit as D or -1.
Example Input/Output I:
Input:
303
Output:
39
Explanation:
The integers from 1 to 30 which have the unit digit as 3
are 3, 13 and 23.
So the sumis39(3+13+23Y
Hence the output is 39
Example Input/Output 2:
Input:
57
Output:
-1
Remove Alphabet
Example Input/Output 1:
Input:
Uv
Output:
ABCDEFGHIJKLMNOPQRSTUWXYZ
Example Input/Output 2:
Input:
LC
Output:
abdefghijklmnopqrstuvwxyz
The program must accept three integers M. N and X as the
input. The program must print the sum of
multiples of X from M to N as the output If there is no
multiple of X from M to N then the program must
print -1 as the output.
Boundary Condition(s):
100
Input Format:
The first line contains the values of M. N and X separated by
space(s).
Output Format:
The first line contains either the sum of multiples of X from M
to N or -1-
Example Input/Output 1:
Input:
5253
Output:
105
Explanation:
The multiples of 3 from 5 to 25 are 6, 9, 12, 15, 18, 21 and 24.
so their sum is 105 9+ 12 + 15 + 18+21+24).
Hence the output is 105
Example Input/Output 2:
Input:
10 20 33
Output:
.1
The program must accept an integer N as the input.
The program must print the factors of N in
descending order as the output
Boundary Condition(s):
1 e-N«-IOOO
Input Format:
The first line contains the value of N.
Output Format:
The first line contains the factors of N in descending
order separated by space(s).
Example Input/Output I:
Input:
24
Output:
2412864321
Explanation:
The factors of 24 in descending order are 24, 12, 8, 6, 4,
3, 2 and I.
Hence the output is 2412 8 6 4 3 2 1
Example Input/Output 2:
Input:
11
Output:
111
Remove Characters Adjacent to Vowels
Boundary Condition(s):
1 <= Length of String <= 1000
Input Format:
The first line contains the string.
Output Format:
The first line contains the string with the characters
adjacent to vowels removed from it.
Example Input/Output 1:
Input:
thinker
Output:
tie
Example Input/Output 2:
Input:
table
Output:
ae
The program must accept a string value S contains
only alphabets as the input The program must print
an alphabet from S which has occurred first in the
alphabetical order as the output.
Note: All alphabets are only lower-case in S.
Boundary Condition(s):
1 Length of S 100
Input Format:
The first line contains a string S.
Output Format:
The first line contains an alphabet from S which has
occurred first in the alphabetical order
Example Input/Output I:
Input:
qwerty
Output:
Explanation:
In the word qwerty, the character 'e' has occurred first
in the alphabetical order.
Hence the output is e
Example Input/Output 2:
Input:
zxsvwu
Output:
7
Remove First X and Last Y Characters
Boundary Condition(s):
2 <= Length of String <= 1000
Input Format:
The first line contains the string S, X and Y separated by
space(s).
Output Format:
The first line contains the string after removal of characters.
Example Input/Output 1:
Input:
marshmallow 2 3
Output:
rshmal
Example Input/Output 2:
Input:
geography 3 1
Output:
graph
The program must accept an integer matrix Of size NXN and
an integer K as the input. The propam must remove the
first K rows and the first K columns from the matrix. Then the
program must print the modified matrix as the output
Boundary Condition(s):
•999 Each element of the matrix < — 999
1 c-K<N
Input Format:
The first line contains the value of N.
The next N lines each contain N integers separated by
space(s).
The line contains the value of K.
Output Format:
The first N-K lines each contain N-K interrs of the modified
matrix separated by a space
Example Input/OutßkJt I:
Input:
4
2021016
2017 116
141613
10 2 174
2
Output:
13
174
Explanation:
Here the value of K is 2. So remove the first 2 rows and the
first 2 columns from the matrix.
Hence the output is
13
174
Remove S2 Characters from S1
Two string values S1 and S2 are passed as input to the program. The
program must remove all the characters that are present in S2 from
S1 and print the resulting string value as the output.
Boundary Condition(s):
1 <= Length of S1 <= 1000
1 <= Length of S2 <= 1000
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The first line contains the string value as mentioned above.
Example Input/Output 1:
Input:
apple
pan
Output:
le
Example Input/Output 2:
Input:
economical
mango
Output:
ecicl
The program must accept a stringS as the input- The program
must print the desired pattern as shown
in the Example Input/Output section
Note; The length of S is always odd.
Boundary Condition(s):
1 Length of S 99
Input Format:
The first line contains the value of string S.
Output Format:
The list of lines containing the desired pattern as shown in
the Example Input/Output section.
Example Input/Output 1:
Input:
skillrack
Output:
skillrack
•carllik
"illra
•••rll
Example Input/Output 2:
Input:
first
Output:
first
•sri
Inverted Triangle with Numbers
Boundary Condition(s):
Input Format:
The first line contains the value of N.
Output Format:
The first N lines containing the desired pattern as
shown in the Example Input/Output section.
undary Condition(s):
1 N 100
nput Format:
e first line contains the value of N.
e second line contains N integers separated by a space.
utput Format:
e first line contains either YES or NO
The program must accept an integer N as the input.
The program must print the desired pattern as shown
in
the Example Input/Output section.
Boundary Condition(s):
1 GNGIOA15
Input Format:
The first line contains the integer N.
Output Format:
The list of lines containing the desired pattern as
shown in the Example Input/Output section.
Example Input/Output l:
Input:
43785
Output:
4
33
8888
55555
Example Input/Output 2:
Input:
10001
Output:
1
00
ooo
0000
Repeating Character Toggle Last
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the output string value.
Example Input/Output 1:
Input:
aaa
Output:
aaA
Example Input/Output 2:
Input:
aahhjhszz
Output:
aAhHjhszZ
The program must accept a string S as the input. The program must
find the count Of alphabets M which are
present bet'vveen the alphabets a and m (inclusive) in the String S.
Then the program must find the count Of
alphabets N which are present betvveen the alphabets n and z
(inclusive) in the String S. Finally, the program
must print the output based on the following conditions,
-If M is greater than N then print FIRSTHALF.
-If N is greater than M then print SECONDHALF.
-If M and N are equal then print •l.
[Link]; The alphabets in S are only in lower case.
Boundary Condition(s):
I Length of S 100
Input Format:
The first line contains the string S.
Output Format:
The first line contains FIRSTHALF or SECONDHALF or -1.
Example Input/Output I:
Input:
abcdxyz
Output:
Fl RSTHALF
Explanation:
The alphabets a, b, c and d are present between the alphabets a and
m. So their count M is 4.
The alphabets x, y and z ere present benjveen the alphabets n and z.
So their count N is 3.
Here M is greater than N. So FIRSTHALF is printed.
Example Input/Output 2:
Input:
ryasnw
Output:
SECONDHALF
Replace Continuously Repeated Characters
Boundary Condition(s):
1 <= Length of string <= 1000
Input Format:
The first line contains the string S.
Output Format:
The first line contains the modified string.
Example Input/Output 1:
Input:
hello
Output:
helo
Example Input/Output 2:
Input:
aabbaaabbcccc
Output:
ababc
The program must accept an integer N as the input. The
program must print valid if N is a prime number
or an even number. Else the program must print invalid as the
output.
Boundary Condition(s):
Input Format:
The first line contains the integer N.
Output Format:
The first line contains either valid or invalid.
Example Input/Output 1:
Input:
53
Output:
valid
Explanation:
The integer 53 is a prime number.
Hence the output is valid
Example Input/Output 2:
Input:
IOO
Output:
valid
Explanation:
The integer 100 is an even number.
Hence the output is valid
Example Input/Output 3:
Input:
Output:
invalid
Replacing Digit With Values In Position
Boundary Condition(s):
1 <= N <= 999999999
Input Format:
The first line contains value of integer N.
Output Format:
The first line contains the resultant number after
replacing every digit of N with the value in the
position.
Example Input/Output 1:
Input:
999999993
Output:
333333339
The program must accept an integer N as the input. The
program must print the sum of the first N terms in
the series given below.
The order of the series must be 1, -2, 3, -4, 5, -6 and so on
(All the odd terms in the series formed from the
positive odd numbers and all the even terms in the series
formed from the negative even numbers).
Boundary Condition(s):
Input Format:
The first line contains the integer N.
Output Format:
The first line contains the sum of the first N terms in the
above mentioned series.
Example Input/Output I:
Input:
5
Output:
3
Explanation:
The first 5 terms are 1, -2, 3, -4 and 5 and their sum is 3 (1
Hence the output is 3
Example Input/Output 2:
Input:
8
Output:
-4
Reverse Last X Digits
Boundary Condition(s):
1 <= N <= 999999999
0 <= X <= 9
Input Format:
The first line contains the value of N.
The second line contains the value of X.
Output Format:
The first line contains the value of N with last X digits
reversed.
Example Input/Output 1:
Input:
12345
2
Output:
12354
Example Input/Output 2:
Input:
123459823
5
Output:
123432895
Reverse Odd Position in String
Boundary Condition(s):
1 <= Length of S <= 100
Input Format:
The first line contains S.
Output Format:
The first line contains the string value with the
characters in the odd positions of S reversed
Example Input/Output 1:
Input:
barcode
Output:
eaocrdb
Example Input/Output 2:
Input:
Mediterranean
Output:
neeiaerrtndaM
Reversed Alphabet Position
Boundary Condition(s):
1 <= Length of String <= 1000
Input Format:
The first line contains S.
Output Format:
The first line contains the specified output.
Example Input/Output 1:
Input:
abc
Output:
zyx
Example Input/Output 2:
Input:
Yarn
Output:
Bzim
The program must accept N intews as the input. The prop-am
must swap the unit diet of the first integer and the
unit diet of Nth integer. The program must swap the unit diet of
the second integer and the unit digit of (N-l)tn
integer and so on. Finally. the program must print the modified
N integers as the output
Boundary Condition(s):
I IOA5
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the modified N integers separated by
space(s).
Example I:
Input:
4
98 5015 19
Output:
9955 1018
Explanation:
The first integer is 98 and its unit digit is 8.
The fourth integer is 19 and its unit diet is 9.
After swappingthe unit digits of 98 and 19.98 becomes 99 and
19 becomes 18.
The second integer is 50 and its unit digit is O.
The third integer is 15 and its unit digit is 5.
After swappingthe unit digits of 50 end 15.50 becomes 55 and
15 becomes IO
Hence the output is 99 55 IO 18
Example Input/Output 2:
Input:
5
8113 8 68 54197
Output:
'''
Reversed Words in Even Positions
Boundary Condition(s):
10 <= Length of S <= 1000
Input Format:
The first line contains the string with two or more words
separated by space(s).
Output Format:
The first line contains the reversed string with words in
the even position reversed.
Example Input/Output 1:
Input:
one two three four
Output:
four eerht two eno
Example Input/Output 2:
Input:
one two three four five
Output:
five ruof three owt one
'''
The program mi-JSt accept string S as the input. The program
mi-JSt print the alphabets Of S in reversal
alphabetical order as the OUtput.
Note: The string S always contain only lowercase alphabets.
Boundary Condition(s):
1 Length of S 100
Input Format:
The first line contains the string S.
Output Formae
The first line contains the alphabets cf S in reversal
alphabetical order.
Example Input/Output 1:
Input:
orange
Output:
rongea
Explanation:
In the string orange, the alphabets in reversal alphabetical
order are r o n g e a.
Hence the output is rongea
Example Input/Output 2:
Input:
Ouput:
Right Angled Triangle Check
1
Three sides of a triangle are passed as input. The program
must print yes if the sides form a right angled triangle. Else
the program must print no.
Boundary Condition(s):
1 <= Length of the sides <= 999999999
Input Format:
The first line contains three integers denoting the length of
the sides separated by a space.
Output Format:
The first line contains yes or no
Example Input/Output 1:
Input:
543
Output:
yes
Example Input/Output 2:
Input:
856
Output:
no
The program must accept a string S as the input. The program
must print the alphabets of S in reversal
alphabetical order as the output.
Note: The string S always contain only lowercase alphabets.
Boundary Condition(s):
I Length of S 100
Input Format:
The first line contains the string S.
Output Format:
The first line contains the alphabets of S in reversal
alphabetical order.
Example Input/Output l:
Input:
orange
Output:
rongea
Explanation:
In the string orange, the alphabets in reversal alphabetical
order are r o n g e a.
Hence the output is rongea
Example Input/Output 2:
Input:
Ouput:
The program must accept a string value S as the input. The
program must print the desired pattern as
shown in the Example Input/Output section.
Boundary Condition(s):
Input Format:
The first line contains the string S.
Output Format:
The first N lines containing the desired pattern as shown in the
Example Input/Output section.
Example Input/Output I:
Input:
happy
Output:
Example Input/Output 2:
Input:
orange
Output:
ar
e gn
The program must accept an integer N as the input The
progarn must print the first N terms in the series the
output.
Note: The order Of series must be 1/4, 1/2, 3/4. I. 5/4,
3/2.7/4, 2.9/4, 5/2 and so on.
Boundary Condition(s):
Input Format:
The first line conatins the integer N.
Output Format:
The first line contains N terms in the series separated
by space-
Example Input/Output 1:
Input:
6
Output:
1/4 1/2 3/415/43/2
Example Input/Output 2:
Input:
9
Output
1/4 1/2 3/4 1 5/4 3/2 7/4 2 9/4
Occurrences X and Y
Boundary Condition(s):
1 X, Y, Each integer value IOA8
Input Format:
The first line contains the value Of N.
The second line contains N integers separated by space(s).
The third line contains the values Of X and Y separated by a
space.
Output Format:
The first line contains either YES or NO.
Boundary Condition(s):
1 <= N <= 999
1 <= K <= 9999999999
Input Format:
The first line contains the integer value of N.
The second line contains N integers separated by space(s).
The third line contains the integer value of K.
Output Format:
The first line contains N integers separated by space(s).
Example Input/Output 1:
Input:
5
12345
2
Output:
45123
Explanation:
After the first rotation, the given array elements are 5 1 2 3 4.
After the second rotation, the given array elements are 4 5 1 2 3.
So, 4 5 1 2 3 is printed.
Example Input/Output 2:
Input:
9
12 23 34 45 6 67 78 89 90
15
Output:
45 6 67 78 89 90 12 23 34
The program must accept a string S as the input, The program
must count the number of occurrences of
each vowel in the string S and print all the vowels along with their
count as the output. The order cf vowels
must be a, e, i, o and u.
Note: All the alphabets in S ere only in lowercase.
Boundary Condition(s):
I Length Of S •$ 1000
Input Format:
The first line contains the string S.
Output Format:
The first line contains the vowel a with its count separated by a
space.
The second line contains the vowel e with its count separated by
a space.
The third line contains the vowel i with its count separated by a
space.
The fourth line contains the vowel o with its count separated by e
space.
The fifth line contains the vowel u with its count separated by a
space.
Example Input/Output l:
Input:
bcdefghijklmnopqrstvwxyz
Output:
Explanation:
The vowel e has occurred once.
The vowel i has occurred once.
The vowel o has occurred once.
Same Characters in Zigzag Matrix
Accept a matrix of size NxN containing only characters as input. The program must print the characters which
are in the same positions in
the forward and the reverse zig-zag traversal. If there is no character in the same position in such traversal
then print -1 as the output.
Boundary Condition(s):
2 <= N <= 20
Input Format:
The first line contains the value of N.
The next N lines contain N characters separated by space.
Output Format:
The first line contains the characters which are in the same positions in the forward and the reverse zig-zag
traversal separated by space(s) or -1.
Output:
achm
Explanation:
In the forward traversal, the matrix contains a, b, c, d, e, j, i, h, g, f, k, l, m, n, o, j, i, h, g, f, k, r, c, f and a.
In the reverse traversal, the matrix contains a, f, c, r, k, f, g, h, i, j, o, n, m, l, k, f, g, h, i, j, e, d, c, b and a.
While traversing in the forward and reverse direction, the characters in the same positions are a, c, h and m as
highlighted in blue color.
Output:
grhvstgo
Output:
-1
The program must accept an integer array of size N
containing only Os and I's as the input. The program
must brins all the zeros to the front and all the ones to the
end of the array. Then the program must print
the modified array as the output.
Boundary Condition(s):
Array Element I
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains N integers of the modified array
separated by a space.
Example Input/Outupt l:
Input:
7
0110100
Output:
0000111
Explanation:
There are 4 zeros and 3 ones in the input,
So print ell the zeros at the beginning and all the ones at the
end.
Hence the output is 00001 1 1
Example Input/Outupt 2:
Input:
4
1110
Output:
Olli
The program must accept an integer N as the input. The
program must print the desired pattern as shown
the Example Input/Output section.
Boundary Condition(s):
1 N 100
Input Format:
The first line contains the value of N.
Output Format:
The first N lines containing the desired pattern as shown in
the Example Input/Output section.
Example Input/Output I:
Input:
5
Output:
12345
12345
Example Input/Output 2:
Input:
8
Output:
12345678
12345678
First and Last N Characters
The propam must accept a string S contains only alphabets and an
integer N as the input. The prop-am must print the
first N alphabets in the string and then print the last N alphabets in
the string as the output.
Boundary Condition(s):
2 Length of S 100
1 N Length of S
Input Format:
The first line contains the string S
The second line contains the integer N.
Output Format:
The first line contains the first N alphabets and the last N alphabets
Skip Traverse from Last
Boundary Condition(s):
2 <= N <= 10000
Input Format:
The first line contains N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains the traversed integers separated by a space.
Example Input/Output 1:
Input:
6
23 17 32 27 14 63
Output:
63 32 23
Example Input/Output 2:
Input:
7
37 19 83 74 3 2 82
Output:
82 3 19
The program must accept a string S and r•uo
characters CHI and CH2 as the input The program
must
replace all the occurrences of CHI by CH2 in the string
S. Then the program must print the modified string as
the output.
Boundary Condition(s):
1 Length Of S G 1
Input Format:
The first line contains the value of the string S.
The second line contains the value cf CHI and CH2
separated by a space.
Output Format:
The first line contains the modified string.
Example Input/Output l:
Input:
terrorist
Output:
teddodist
Explanation:
All the occurrences of 'r' are replaced by 'd' in the
string "terrorist".
Hence the output is teddodist
Example Input/Output 2:
Input:
manipulasicn
Output:
manipulation
Sort Odd Even Array
Boundary Condition(s):
1 <= N <= 99999
Input Format:
The first line contains N.
The second line contains N integers separated by space.
Output Format:
The first line contains N integers separated by space.
Example Input/Output 1:
Input:
7
12 45 14 21 57 12 9
Output:
9 45 12 21 14 12 57
Example Input/Output 2:
Input:
10
78 121 34 56 12 34 89 18 33 90
Output:
78 18 34 34 12 56 89 90 33 12
The program must accept N integers (where N is always even)
as the inpu'„ The program must sort every
uo integers in ascending order among the N integers. Then the
program must print the modified value of
all the N integers as the output.
Boundary Condition(s):
2 G NG 100
I Each integer value 9999
Input Format:
The first line contains the value of N.
The second line contains N integers separated by space(s).
Output Format:
The first line contains N integer values separated by a space.
Example Input/Output 1:
Input:
4
10524
Output:
51024
Explanation:
The first two integers are IO and 5. So sort them in ascending
order.
The next two integers are 2 and 4, They are already sorted in
ascending order. So no need to sort them
again.
Hence the output is 5 IO 2 4
Example Input/Output 2:
Input:
8
36 22 10
Output:
22 36 87 87 44 54 10 93
he program must accept a stringS contains only al phabets
and an integer N as the input. The program must print the
'rst N alphabets in the string and then print the last N
alphabets in the string as the output-
Boundary Condition(s):
2 Length of S 100
I N Length of S
Input Format:
The first line contains the string S
he second line contains the integer N.
he first line contains the first N alphabets and the last N
alphabets
Example Input/Output I:
Input:
Engineering
3
Output:
Enging
Explanation:
he first 3 alphabets in the string "Engineering • are E n g.
he last 3 alphabets in the string "Engneering• are i n g.
Hence the output is Eneng
Example Input/Output 2:
Input:
irst
5
Output:
irstfirst
Sort One or Two Digit Numbers
N numbers are passed as input. The program must sort only the
numbers with one or two digits in it among the N numbers. Other
numbers are retained in their same positions.
Boundary Condition(s):
1 <= N <= 1000
Input Format:
The first line contains N.
The second line contains N numbers separated by space(s).
Output Format:
The first line contains N numbers separated by a space.
Example Input/Output 1:
Input:
6
12 109 3 751 89 56
Output:
3 109 12 751 56 89
Example Input/Output 2:
Input:
9
534 95 805 605 315 42 762 523 23
Output:
534 23 805 605 315 42 762 523 95
Sort Strings -Unique Alphabets Count
N string values are passed as input. The program must sort and print the strings based on
the count of unique alphabets in them. If two strings have same unique alphabet count,
then sort them based on lexicographical order. Sorting based on the count of unique
characters must be done in descending order (that is the string having the highest unique
character count must be printed first).
Boundary Condition(s):
1 <= N <= 100
1 <= Length of string <= 1000
Input Format:
The first line contains N.
The next N lines contain the values of N strings.
Output Format:
The first N lines contain the string values sorted based on the given conditions.
Example Input/Output 1:
Input:
3
bubble
telegram
munch
Output:
telegram
munch
bubble
Example Input/Output 2:
Input:
4
sit
miner
flood
temple
Output:
miner
temple
flood
String Alphabets Position Sum
Boundary Conditions:
1 <= L <= 100
Output:
The first line contains the sum of positions of the lower case
alphabets in S.
Example Input/Output 1:
Input:
abca
Output:
7
Explanation:
The sum of positions is 1+2+3+1 = 7
Example Input/Output 2:
Input:
azd
Output:
31
String Characters Interlace
Given an input string S, accept the input string S and print the string
in the interlaced order as shown in the example Input/Output
section.
Input Format:
The first line contains the value of String S (may contain letters, white
spaces, special characters, and numbers).
Output Format:
The string S has to be printed in the order of 1st character and (N-1)
character, 2nd character and (N-2) character and so on where N is the
length of the string S.
Boundary Conditions:
1 <= Length of S <= 100
Example Input/Output 1:
Input:
abc321
Output:
a1b2c3
Example Input/Output 2:
Input:
pqrs-wxyz
Output:
pzqyrxsw-
String With Most Vowels
Boundary Condition(s):
1 <= length of strings <= 1000
Input Format:
The first line S1 and S2 separated by space(s).
Output Format:
The first line contains a string.
Example Input/Output 1:
Input:
adder divider
Output:
divider
Example Input/Output 2:
Input:
important welcome
Output:
important
Given a string S and an integer N as the input, the program must split the string into groups
whose size is N and print them as the
output in separate lines in a zig zag manner. If the last group size is less than N then the
remaining letters must be filled with
asterisk as shown in the Example Input/Output.
Input Format:
The first line contains S.
The second line contains N.
Output Format:
LENGTH(S)/N + LENGTH(S)%N lines containing the desired pattern.
Boundary Conditions:
4 <= LENGTH(S) <= 500
2 <= N <= LENGTH(S)
Example Input/Output 1:
Input:
ENVIRONMENT
3
Output:
ENV
ORI
NME
*TN
Example Input/Output 2:
Input:
ENVIRONMENT
4
Output:
ENVI
MNOR
ENT*
Example Input/Output 3:
Input:
EVERYDAY
2
Output:
EV
RE
YD
YA
Lower Triangle Matrix
Given a square matrix of size N as the input, print the lower triangular matrix form
of the matrix as shown in the Example Input/ Output section.
Boundary Conditions:
1 <= N <= 50
Output:
The first N lines represent the lower triangular matrix format of the matrix.
Output:
1
45
789
Output:
1
56
912
4567
Structure Laptop with Minimum Cost
The program must accept an integer X followed by the brand name or the
product number of N laptops with their costs.
The program must print either the brand name or the product number of a
laptop which has the minimum cost among N laptops.
If X is 1 then X is followed by the brand name. If X is 2 then X is followed by the
product number. Fill in the missing lines of code so that
the program runs successfully.
Note: If two or more laptops have the same cost then print the information of
first occurring laptop.
Input Format:
The first line contains the value of N.
The next N lines contain an integer, a string (brand name) or an integer (product
number) and an integer (cost) separated by space(s).
Output Format:
The first line contains either a string (brand name) or an integer (product
number) of the laptop which has the minimum cost among N laptops.
Example Input/Output 1:
Input:
4
1 Sony 70000
2 89793456 30000
2 65765767 60000
1 HP 45000
Output:
89793456
Example Input/Output 2:
Input:
3
1 Samsung 50000
2 76576777 45000
1 Acer 20000
Output:
Acer
Given an integer N, the program must print the pattern as shown in
the Example Input/Output section.
Boundary Condition(s):
1 <= N <= 100
Input Format:
The first line contains N.
Output Format:
The pattern is printed as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
4
Output:
1*2*3*4
*7*6*5*
**8*9**
***10***
Example Input/Output 2:
Input:
5
Output:
1*2*3*4*5
*9*8*7*6*
**10*11*12**
***14*13***
****15****
2*2 Sub Matrix with Sum
A matrix of size R*C and an integer S are passed as the input to the program.
The program must print the 2*2 submatrix whose sum is S.
If more than one such submatrices exist, print the first occurring submatrix
(when traversed from top to bottom in the matrix and from
left to right in each row).
Boundary Condition(s):
2 <= R, C <= 100
Input Format:
The first line contains the value of R and C separated by space(s).
The next R lines contain C integers separated by space(s).
Output Format:
The first two lines contain the submatrix.
Example Input/Output 1:
Input:
33
23 12 45
25 26 29
33 35 36
119
Output:
25 26
33 35
Example Input/Output 2:
Input:
43
48 10 77
4 99 15
75 29 97
40 84 62
272
Output:
29 97
84 62
Cut the Cake
Initial size of a cake and values of position of N cuts are passed as the input.
The program must print the size of largest cake piece after the N cuts.
Boundary Condition(s):
10 <= N <= 999999
Input Format:
The first line contains the size of cake.
The second line contains the values of position of N cuts in ascending order.
Output Format:
The first line contains the size of largest cake piece.
Example Input/Output 1:
Input:
16
358
Ouput:
8
Explanation :
After the first cut the size of piece 1 is 3, after the second cut the size of piece
2 is 2,after the third cut the size of piece 3 is 3 and after the fourth cut the size
of piece 4 is 8.
Finally the largest cake piece is 8.
Example Input/Output 2:
Input:
25
5 10 16
Ouput:
9
T String Pattern
Given two strings S1 and S2, the program must print the pattern as shown in the
Example Input/Output section.
Note:
The string S1 always comes in the first row.
The string S2 is printed along the last matching column of S1.
Boundary Condition(s):
1 <= Length of S1, S2 <= 100
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The pattern is printed as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
trophy
panther
Output:
trophy
---a--
---n--
---t--
---h--
---e--
---r--
Example Input/Output 2:
Input:
morning
ninja
Output:
morning
-----i-
-----n-
-----j-
-----a-
X in Rectangular Pattern
The program must accept an integer N as the input. The program must print the
pattern as shown in the Example Input/Output sections.
Boundary Condition(s):
5 <= N <= 50
Input Format:
The first line contains the value of N.
Output Format:
The first N lines contain the desired pattern as shown in the Example Input/Output
sections.
Example Input/Output 1:
Input:
15
Output:
***************
**-----------**
*-*---------*-*
*--*-------*--*
*---*-----*---*
*----*---*----*
*-----*-*-----*
*------*------*
*-----*-*-----*
*----*---*----*
*---*-----*---*
*--*-------*--*
*-*---------*-*
**-----------**
***************
E
xample Input/Output 2:
Input:
20
Output:
********************
**----------------**
*-*--------------*-*
*--*------------*--*
*---*----------*---*
*----*--------*----*
*-----*------*-----*
*------*----*------*
*-------*--*-------*
*--------**--------*
*--------**--------*
*-------*--*-------*
*------*----*------*
*-----*------*-----*
*----*--------*----*
*---*----------*---*
*--*------------*--*
*-*--------------*-*
**----------------**
********************
'''
Vowels and Consonants
Boundary Condition(s):
1 <= Length of S <= 200
Example Input/Output 1:
Input:
elephant
Output:
eealphnt
Explanation:
Here the vowels are "eea" and the consonants are "lphnt"
Hence the output is "eealphnt".
Example Input/Output 2:
Input:
HETEROGENEOUS
Output:
EEOEEOUHTRGNS
Template Strings Count
A template is a special string which can be used to generate multiple strings consisting of characters from the
template. For example, the template string ab can be used to generate strings ab, aba, bab, aabb, bbaa, babb,
bbaba and so on. N strings are passed as the input. The program must print the number of templates used in
generating the N strings.
Note:
All the characters from the template must be present in the generated string.
Template string must not have any repeated characters in it.
The order of the characters in template strings are ignored (i.e. abc is same as bca).
Boundary Condition(s):
1 <= N <= 100
1 <= Length of string <= 100
Input Format:
The first line contains N.
The second line contains N strings separated by space(s).
Output Format:
The first line contains the count of the templates used.
Example Input/Output 1:
Input:
5
abc abaa banana ban caba
Output:
3
Explanation:
The template string abc is used to generate the strings abc and caba.
The template string ab is used to generate the string abaa.
The template string abn is used to generate the strings banana and ban.
So there are three template strings used to generate the five strings.
Example Input/Output 2:
Input:
6
aaaa bbbb aa bbb red re
Output:
4
Input:
3
aa aaa a
Expected Output:
1
Trapezium Pattern Printing
Input Format:
The first line contain N.
Boundary Conditions:
2<=N<=100
Example Input/Output1:
Input:
4
Output:
1*2*3*4*17*18*19*20
--5*6*7*14*15*16
----8*9*12*13
------10*11
Example Input/Output2:
Input:
7
Output:
1*2*3*4*5*6*7*50*51*52*53*54*55*56
--8*9*10*11*12*13*44*45*46*47*48*49
----14*15*16*17*18*39*40*41*42*43
------19*20*21*22*35*36*37*38
--------23*24*25*32*33*34
----------26*27*30*31
------------28*29