0% found this document useful (0 votes)
12 views42 pages

Python Average Challenges

The document outlines various programming problems with specific input and output formats, including tasks like printing Floyd's triangle, reversing words in a string, calculating soccer team scores, and checking password validity. Each problem includes boundary conditions and example inputs/outputs to clarify requirements. The problems cover a range of topics suitable for coding challenges or assessments.

Uploaded by

hisil45905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views42 pages

Python Average Challenges

The document outlines various programming problems with specific input and output formats, including tasks like printing Floyd's triangle, reversing words in a string, calculating soccer team scores, and checking password validity. Each problem includes boundary conditions and example inputs/outputs to clarify requirements. The problems cover a range of topics suitable for coding challenges or assessments.

Uploaded by

hisil45905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Pattern Printing - Floyd Triangle

ID:2615

Solved By 13046 Users

A number N indicating the number of rows in Floyd's triangle is passed as the input. The program must print the
Floyd's triangle pattern.
Input Format:
The first line will contain N.
Output Format:
The first N lines will contain the Floyd's triangle pattern.
Boundary Conditions:
3 <= N <= 50
Example Input/Output 1:
7
Output:
1
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28

Example Input/Output 2:
Input:
5
Output:
1
23
456
7 8 9 10
11 12 13 14 15

Max Execution Time Limit: 5000 millisecs


String - Reverse Words [ZOHO]

ID:2613

Solved By 8651 Users

A string S is passed as the input. The program must reverse the order of the words in the string and print them as
the output.
Input Format:
The first line will contain S.
Output Format:
The first line will contain the words in the string S in the reverse order.
Boundary Conditions:
Length of S is from 5 to 100.
Example Input/Output 1:
Input:
Today is Friday
Output:
Friday is Today
Example Input/Output 2:
Input:
five six ten eleven
Output:
eleven ten six five

Max Execution Time Limit: 5000 millisecs


Series Team Score

ID:2621

Solved By 7361 Users

Two soccer teams A and B play a series of matches over a period of time. In a match, the winning team gets 3
points. If the match ends in a tie (draw) with both teams scoring same goals, then both the teams get one point
each. The losing team does not get any point.
The program must accept the goals scored by both team A and B in certain number of matches and print the
cumulative scores of team A and B separated by a space.
Input Format:
First line will contain the goals scored by team A, with the goal values separated by a space.
Second line will contain the goals scored by team B, with the goal values separated by a space.
Output Format:
First line will contain the scores of team A and B separated by a space.
Boundary Conditions:
The length of the input with the space separated goals is from 3 to 100.
Example Input/Output 1:
Input:
351
320
Output:
71
Explanation:
Team A drew the first match and hence both team A and B got one point each.
Team A won both matches two and three and hence got additional 6 points.
So the final score of team A is 7 and team B is 1.
Max Execution Time Limit: 5000 millisecs
Odd Length String Diagonal Pattern [ZOHO]

ID:2611

Solved By 6591 Users

An odd length string S of length L is passed as the input. The program must print the string S as two diagonals as
shown in the example Input/Output below.
Input Format:
The first line will contain S.
Output Format:
L lines will contain the pattern as shown in the example Input/Output below.
Boundary Conditions:
Length of S is from 3 to 51.
Example Input/Output 1:
Input:
cry
Output:
cy
r
cy
Example Input/Output 2:
Input:
tiger
Output:
t r
ie
g
ie
t r

Max Execution Time Limit: 5000 millisecs


Array Product Except Index Value [AMAZON]

ID:2618

Solved By 6432 Users

An array of N integers with non-zero values is passed as the input to the program. The program must print another
array of size N where value at each index will be the product of all values in the input array except the value at that
index in the input array.
Input Format:
The first line will contain N integers separated by a space.
Output Format:
The first line will contain N integers separated by a space.
Boundary Conditions:
The length of the input containing N integers will be from 3 to 100.
The integer values will be from 1 to 100.
Example Input/Output 1:
Input:
12345
Output:
120 60 40 30 24
Example Input/Output 2:
Input:
10 5 4
Output:
20 40 50
Example Input/Output 3:
Input:
21 100
Output:
100 21

Max Execution Time Limit: 5000 millisecs


String - Count Articles

ID:2617

Solved By 6102 Users

A string S is passed as the input. The program must print the number of articles ( a, an and the) in S.
The string S passed as the input NEED NOT be correct grammatically.
Input Format:
The first line will contain S
Output Format:
The first line will contain the count of articles in S.
Boundary Conditions:
The length of the string S will be from 3 to 1000.
Each word in S will not be more than 100 characters.
Example Input/Output 1:
Input:
I went to a movie yesterday along with an old man.
Output:
2
Example Input/Output 2:
Input:
In 1885 it was banished from the shelves of the Concord Public Library, an act that attracted a lot of publicity and
discussion in the press. It is still frequently in the news, as various schools and school systems across the country
either ban it from or restore it to their classrooms. The texts and illustrations below attempt to capture both the
novel's achievement and some aspects of its controversiality.
Output:
8

Max Execution Time Limit: 5000 millisecs


Sub Palindromes

ID:2619

Solved By 5391 Users

Given a string S, the program must print the count of sub palindromes (with a minimum length of two characters)
in the string S.
Boundary Conditions:
Length of the string is between 2 and 200.
Input Format:
First line will contain the string value S.
Output Format:
First line will contain the integer which represents the count of sub palindromes in the string S.

Sample Input/Output:
Example 1:
Input:
everest
Output:
2
Explanation:
The sub palindromes are eve, ere

Example 2:
Input:
abccbaab
Output:
5
Explanation:
The sub palindromes are cc, bccb, aa, baab, abccba

Max Execution Time Limit: 10000 millisecs


Message Encryption

ID:2620

Solved By 4810 Users


To encrypt messages Jil will first decide on the number of columns C to use. Then Jil will pad the message with
letters chosen randomly so that they form a rectangular matrix. Finally Jil will write down the message navigating
the rows from left to right and then from right to left.
The program must accept the encrypted message M as input and then extract and print the original message
(along with any additional padding letters) from the encrypted one based on the value of C.

Boundary Conditions:
Length of M is from 4 to 200.
2 <= C <= 20

Input Format:
First line will contain the string value of the encrypted message M.
Second line will contain the integer value of the column used for the encryption.
Output Format:
First line will contain the string value of the original message (along with any additional padding letters)

Sample Input/Output:
Example 1:
Input:
midinadiazne
3
Output:
madeinindiaz
Explanation:
mid
ani
dia
enz
Here z is the padding letter. The navigating across the rows mid (left to right) ina (right to left) and so on we come
up with the encrypted message midinadiazne.

Example 2:
Input:
loaesfbnaiordilertenrdhdw
5
Output:
lionroaredandthebirdsflew
Explanation:
loaes
ianbf
ordil
netre
rdhdw
Here there are no padding letters. The navigating across the rows left to right and then from right to left we get
loaesfbnaiordilertenrdhdw

Max Execution Time Limit: 10000 millisecs


Minimum Distance Between Words [AMAZON]

ID:2614
Solved By 4435 Users

A string S is passed as the input. Two words W1 and W2 which are present in the string S are also passed as the
input. The program must find the minimum distance D between W1 and W2 in S (in forward or reverse order) and
print D as the output.
Input Format:
The first line will contain S.
The second line will contain W1.
The third line will contain W2.
Output Format:
The first line will contain D - the minimum distance between W1 and W2 in S.
Boundary Conditions:
Length of S is from 5 to 200.
Example Input/Output 1:
Input:
the brown quick frog quick the
the
quick
Output:
1
Explanation:
quick and the are adjacent as the last two words. Hence distance between them is 1.
Example Input/Output 2:
Input:
the quick the brown quick brown the frog
quick
frog
Output:
3

Max Execution Time Limit: 5000 millisecs


String - Count Articles

ID:2617

Solved By 6102 Users

A string S is passed as the input. The program must print the number of articles ( a, an and the) in S.
The string S passed as the input NEED NOT be correct grammatically.
Input Format:
The first line will contain S
Output Format:
The first line will contain the count of articles in S.
Boundary Conditions:
The length of the string S will be from 3 to 1000.
Each word in S will not be more than 100 characters.
Example Input/Output 1:
Input:
I went to a movie yesterday along with an old man.
Output:
2
Example Input/Output 2:
Input:
In 1885 it was banished from the shelves of the Concord Public Library, an act that attracted a lot of publicity and
discussion in the press. It is still frequently in the news, as various schools and school systems across the country
either ban it from or restore it to their classrooms. The texts and illustrations below attempt to capture both the
novel's achievement and some aspects of its controversiality.
Output:
8

Max Execution Time Limit: 5000 millisecs


Sub Palindromes

ID:2619

Solved By 5391 Users

Given a string S, the program must print the count of sub palindromes (with a minimum length of two characters)
in the string S.
Boundary Conditions:
Length of the string is between 2 and 200.
Input Format:
First line will contain the string value S.
Output Format:
First line will contain the integer which represents the count of sub palindromes in the string S.

Sample Input/Output:
Example 1:
Input:
everest
Output:
2
Explanation:
The sub palindromes are eve, ere

Example 2:
Input:
abccbaab
Output:
5
Explanation:
The sub palindromes are cc, bccb, aa, baab, abccba
Max Execution Time Limit: 10000 millisecs
Tower Line of Sight Issue

ID:2616

Solved By 3722 Users

Four towers A, B, C, D are to be erected. Tower A is to communicate with tower C. Tower B is to communicate
with tower D.
Line of sight issue can occur under the following conditions
- when tower B or D is in the straight line connecting A and C
- when tower A or C is in the straight line connecting B and D
The program must accept the co-ordinates of all four towers and print yes or no depending on whether Line of
sight issue will occur or not.
Input Format:
The first line will contain X and Y co-ordinates of tower A separated by a space.
The second line will contain X and Y co-ordinates of tower B separated by a space.
The third line will contain X and Y co-ordinates of tower C separated by a space.
The fourth line will contain X and Y co-ordinates of tower D separated by a space
Output Format:
The first line will contain yes or no (smaller case)
Boundary Conditions:
The value of the co-ordinates will be from -500 to 500.
Example Input/Output 1:
00
0 -2
20
02
Output:
yes

Example Input/Output 2:
Input:
00
0 -2
20
0 -5
Output:
no

Max Execution Time Limit: 5000 millisecs


Shift Encryption

ID:242

Solved By 5164 Users


Anmol wants to encrypt the message M which is to be sent to his business partner Binamol. So he shifts every
alphabet by X positions in forward direction and he adds Y to every number in the message.
Given a string value M of the message and the values of X and Y, the program must print the encrypted message E.
- All the alphabets will be in lower case.
- Spaces and special characters in the message M should be reproduced as such in the encrypted message E.
Input Format:
First line will contain the string value M
Second line will contain the integer value of X
Third line will contain the integer value of Y
Output Format:
First line will contain the string value of the encrypted message E.
Constraints:
Length of M is from 2 to 100.
0 <= X <= 10
0 <= Y <= 9
Sample Input/Output:
Example 1:
Input:
call me at 10 p.m
2
1
Output:
ecnn og cv 21 r.o

Example 2:
Input:
credit 1 lakh
3
0
Output:
fuhglw 1 odnk

Max Execution Time Limit: 5000 millisecs


Strong password check

ID:221

Solved By 4910 Users

Recently a security committee decided to enforce the following rules when an employee creates/changes his/her
password.
- The password must contain atleast one special character among # ! _ $ @
- The password must contain atleast two numbers
- The password must contain atleast one upper case alphabet and one lower case alphabet.
- The password must have a minimum length of 8.
- The password must have a maximum length of 25.
The program must accept a given password string P as input and check for these rules and output VALID or
INVALID.
Boundary Conditions:
Length of P is from 2 to 50.
Input Format:
First line will contain the string value of the password P
Output Format:
VALID or INVALID based on the check performed by the program by applying the rules.
Example Input/Output:
Example 1:
Input:
kiC_3b0x3r
Output:
VALID
Example 2:
Input:
m@d31nindia
Output:
INVALID
Explanation:
No alphabet in uppercase.
Example 3:
Input:
M1kT!s0
Output:
INVALID
Explanation:
Minimum length must be 8

Max Execution Time Limit: 5000 millisecs


Length of the line

ID:209

Solved By 4826 Users

A line is denoted by the x and y co-ordinates of the two end points. The program must print the length of the line.

Input Format:
First line will contain the x and y co-cordinates of point 1 separated by a space.
Second line will contain the x and y co-cordinates of point 2 separated by a space
Output Format:
The length of the line rounded up to two decimal places. If there is no floating point representation then a .00 is to
appear at the end of the output.
Sample Input/Output:
Example 1:
Input:
04
30
Output:
5.00

Example 2:
Input:
22
14 7
Output:
13.00
Example 3:
Input:
00
33
Output:
4.24

Max Execution Time Limit: 5000 millisecs


Incorrect keyboard

ID:215

Solved By 4543 Users

Suman's keyboard got damaged as he dropped it from a considerable distance. As a result instead of K the
keyboard may sometimes display T (but will never display K instead of T)
Similarly instead of G, the keyboard may sometimes display D, instead of R sometimes it may display L and
sometimes instead of R it displays F.
Because of this Suman has to think of all possible words for a displayed word (obtained by typing using his
keyboard). The program to be written should accept a word W which is displayed as a result of typing on Suman's
keyboard and should calculate how many possible words it could mean (if typed using a properly working
keyboard) and print the count as the output.
Boundary Conditions:
The length of the input word is between 2 and 100.
Input Format:
First line will contain the word W.
Output Format:
The count of possible words that the input word (typed using Suman's keyboard) could mean.

Sample Input/Output:
Example 1:
Input:
FILIPEK
Output:
4
Explanation:
The words that may be wrongly typed are F and L. Here F could be correctly typed or wrongly typed instead of R.
Similarly L could be correctly typed or wrongly typed instead of R.
Hence the overall words to be considered are 2*2 = 4.
Note: K is not considered as K will not be typed instead of some other letter. Only instead of K sometimes T will be
typed.

Example 2:
Input:
KICKED
Output:
2
Explanation:
D could be correctly typed or wrongly typed instead of G. Hence overall words to be considered = 2.

Example 3:
Input:
FUTILE
Output:
8
Explanation:
F,T,L - These three letters can be wrongly typed instead of R,K,R or can be correctly typed. Hence overall words to
be considered = 2*2*2 = 8.

Max Execution Time Limit: 5000 millisecs


Minimum Sum - M out of N

ID:2622

Solved By 4410 Users

Given N positive integers, find the minimum sum S that can be obtained by adding exactly M out of the N integers.
The program must print the value of the minimum sum S.
Input Format:
The first line will contain N and M separated by a space.
The second line will contain the values of N positive integers separated by a space.
Output Format:
First line will contain S.
Boundary Conditions:
3 <= N <= 50
2 <= M <= N
Example Input/Output 1:
Input:
52
92154
Output:
3
Explanation:
Out of the five given numbers, the sum of 1+2 = 3 is the least sum and hence printed as the output.

Max Execution Time Limit: 5000 millisecs


Arrays - Distinct Elements Count

ID:2624

Solved By 4381 Users

Two integer arrays of length L1 and L2 are passed as input. The program must print the count of the distinct
elements present in both the arrays.
That is the program must print the count of integer values that are present in the first array but not in the second
array plus the count of integer values that are present in the second array but not in the first array.
Input Format:
The first line will contain L1 and L2 separated by a space.
The second line will contain the L1 integer values separated by a space.
The third line will contain the L2 integer values separated by a space.
Output Format:
First line will contain the integer value which is the count of the distinct elements in both the arrays.
Boundary Conditions:
1 <= L1 <= 50
1 <= L2 <= 50
Example Input/Output 1:
Input:
45
1 5 9 10
22 5 12 9 5
Output:
4
Explanation:
The distinct elements present in first array are 1, 10 and in the second array are 22, 12.
Example Input/Output 2:
Input:
32
100 200 300
201 600
Output:
5

Max Execution Time Limit: 5000 millisecs


Choose Items For Highest Discount.
ID:234

Solved By 4340 Users

Chandru went for shopping and he was offered N number of items at various discount percentage rates. Out of
these N items he wants to choose N-1 items such that the amount he saves is maximum.
The program must print the item which is to be left out.
Input Format:
First line will contain the value of N - number of items
N lines containing item name, label price and the discount percentage separated by one or more spaces.
Output Format:
The name of the item which is not to be purchased as it offers least discount.
Boundary Conditions:
2 <= N <= 20
The length of the item name string value is from 1 to 100.
The price of the item is from 1 to 999999
Example Input/Output 1:
Input:
3
harddisk 4000 20
monitor 15000 10
laptop 30000 5
Output:
harddisk
Explanation:
harddisk savings = 800, monitor savings = 1500, laptop savings = 1500. Hence harddisk is offering least savings
and is to be left out.

Max Execution Time Limit: 5000 millisecs


Strict Professor - Class Cancellation

ID:2623

Solved By 4047 Users

In a college, a professor is strict and mandates that at least M students out of the total N students must arrive on
time to his class. Else he would cancel the class. The start time of the class is also passed as the input. The
individual arrival time for N students is also passed as input in 24 hour format.
The program must print if the class was cancelled or not.
Input Format:
The first line will contain N and M separated by a space.
The second line will contain the start time of the class.
The third line will contain the arrival time of the N students separated by one or more space(s).
Output Format:
First line will contain either Yes or No (Yes for cancellation of the class and No if the class is not cancelled).
Boundary Conditions:
3 <= N <= 50
2 <= M <= N
Example Input/Output 1:
Input:
53
9:30
9:30 9:38 9:31 9:32 9:31
Output:
Yes
Explanation:
4 out of the 5 students arrived late, which means only one arrived on time. As the professor has mandated 3 out of
the 5 must arrive on time, the class was cancelled and hence Yes is printed as the output.
Example Input/Output 2:
Input:
64
11:10
10:30 10:40 10:55 11:20 11:10 11:12
Output:
No

Max Execution Time Limit: 5000 millisecs


Order by prime, odd and even

ID:237

Solved By 3793 Users

A set of numbers of size N which are separated by one or more spaces will be passed as input. The program
should print the prime numbers first followed by odd numbers and finally even numbers.
Each of these categories, prime numbers, odd numbers and even numbers must be sorted in ascending order
among themselves. The numbers which are prime must be excluded from the list of odd and even numbers (In the
case of even numbers only 2 is prime as well as even)
Input Format:
First line will contain the set of numbers separated by one or more spaces.
Output Format:
First line will contain the prime numbers, odd numbers, even numbers in the same order sorted in ascending
order. The numbers must be separated exactly by one space.
Constraints:
Size of the set N will be from 2 to 20.
Example Input/Output 1:
Input:
4 5 9 22 11 2 15
Output:
2 5 11 9 15 4 22

Example Input/Output 2:
Input:
611953 494147 493137 493133 493138
Output:
493133 494147 611953 493137 493138
Explanation:
493133 494147 611953 are prime numbers.

Max Execution Time Limit: 5000 millisecs


Filling Cans

ID:219

Solved By 3481 Users

Two cans are with capacity X and Y liters. The program must determine the number of steps required to obtain
exactly Z litres of liquid in one of the cans.
At the beginning both cans are empty. The following operations are counted as "steps".
- emptying a vessel,
- filling a vessel,
- pouring liquid from larger can to the smaller, without spilling, until one of the cans is either full or empty.
If it is not possible to obtain Z liters exactly then the output must be -1.
Boundary Conditions:
0 < X <= 100
0 < Y <= 100
0 < Z <= 100
Input Format:
First line will contain the value of X
Second line will contain the value of Y
Third line will contain the value of Z
Output Format:
The number of steps required as an integer. If it is not possible to obtain Z liters then the output is -1.

Sample Input/Output:
Example 1:
Input:
5
2
3
Output:
2
Explanation:
Here X=5, Y=2
Step 1: Pour 5 liters of liquid into 5 liter can
Step 2: Pour 2 liters from 5 liter can into 2 liter can.
Now the 5 liter can will have 3 liters which is Z. Hence 2 steps are required.
Example 2:
Input:
2
3
4
Output:
-1
Explanation:
Z is greater than X and Y. Hence it is not possible to have 4 liters in any one of the cans. Hence output is -1.

Max Execution Time Limit: 5000 millisecs


Reverse and remove letters in vowel positions

ID:243

Solved By 5300 Users

Sharon does not like vowels. So she wants to remove vowels from any string. But her friend Jennie loves vowels
and wants to retain vowels in as string. So both discuss and agree to the following condition.
- They will reverse the string value and then remove the letters in the positions of the vowels in the original string.
Help them by writing the program implementing the above condition.
Input Format:
First line will contain the string value S.
Output Format:
First line will contain the reversed string value with the letters in the positions of vowels in the original string
removed.
Constraints:
Length of String S is from 2 to 50.

Sample Input/Output:
Example 1:
Input:
environment
Output:
nenrine
Explanation:
The reversed string value is tnemnorivne.
The vowels position in the original string are e-1 i-4 o-6 e-9
Hence after removing the letters in the positions 1,4,6,9 the string is nenrine

Example 2:
Input:
pond
Output:
dop
Explanation:
The reversed string value is dnop.
The vowels position in the original string are o-2
Hence after removing the letters in the positions 2 the string is dop
Max Execution Time Limit: 5000 millisecs
Adamant Kid

ID:233

Solved By 4966 Users

An adamant kid keeps on repeating the stuff he wants. Like if the kid wants chocolate he keeps repeating
"chocolate". Given the stuff the child is demanding the program must print if the character in two given positions X,
Y is same or not by printing YES or NO.
Input Format:
First line will contain the name of the stuff as a string value S.
Second line will contain two integer values X, Y denoting the position of the characters. The values of X and Y are
separated by a space.
Output Format:
First line will contain YES or NO
Boundary Conditions:
Length of S is from 2 to 100.
Sample Input/Output:
Example 1:
Input:
icecream
4 10
Output:
YES
Explanation:
As the kid keeps on repeating icecream, the 10th position character will also be c in ice creamicecream.
As the characters in 4th and 10th position are same (that is c) the output is YES
Example 2:
Input:
cake
2 12
Output:
NO
Explanation:
When cake is repeated like cakecakecakecake, the character in 12th position is e which is NOT equal to the
character a in 2nd position. Hence the output is NO.

Max Execution Time Limit: 5000 millisecs


Find the digital sum

ID:214

Solved By 4753 Users


A number N is passed as an input to the program. The program must print the digital sum of the number.
Note: The digital sum of a number is defined as the recursive sum of digits of a number till it reaches a single digit.
Boundary Conditions:
0 < N < 10000000
Input Format:
First line will contain the number N.
Output Format:
First line will contain the digital sum of the number N.
Sample Input/Output:
Example 1:
Input:
45102
Output:
3
Explanation:
4+5+1+0+2 = 12. But 12 is a two digit number. We need to recursively add till the sum is a single digit. So 1+2 = 3.

Example 2:
Input:
22311
Output:
9
Explanation:
2+2+3+1+1 = 9

Example 3:
Input:
9879871
Output:
4
Explanation:
9+8+7+9+8+7+1 = 49. But 49 is a two digit number. We need to recursively add till the sum is a single digit. So 4+9 =
13.
So again adding 1+3=4

Max Execution Time Limit: 5000 millisecs


Find AM or PM

ID:204

Solved By 4503 Users


A string S which represents the time in 24 hour format HH:MM is passed as input. The program must find if it is AM
or PM and print it as output.
If an invalid time is passed as input, the program must print INVALIDINPUT
Boundary Conditions:
12:00 is noon and PM must be printed as output.
00:00 or 24:00 is midnight and AM must be printed as output.
Input Format:
First line will contain the string value S which represents the time in HH:MM format.
Output Format:
The first line will contain the output which is either AM or PM
IMPORTANT: The output is case sensitive. Hence print AM or PM in upper case.
Sample Input/Output:
Example 1:
Input:
13:44
Output:
PM
Example 2:
Input:
12:00
Output:
PM
Example 3:
Input:
32:70
Output:
INVALIDINPUT
Example 4:
Input:
05:32
Output:
AM

Max Execution Time Limit: 5000 millisecs


Next Number Palindrome

ID:226

Solved By 4361 Users

Given a number N, the program must print the next palindromic number P.
Boundary Conditions:
9 < N < 100000
Input Format:
First line will contain the number N
Output Format:
First line will contain the next palindromic number P.
Sample Input/Output:
Example 1:
Input:
909
Output:
919
Example 2:
Input:
2131
Output:
2222

Max Execution Time Limit: 5000 millisecs


Character B follows A

ID:225

Solved By 4332 Users

Given a string S and two characters A, B the program must print the number of occurrences where A is followed
by B.
Boundary Conditions:
Length of the string S is between 2 and 200.
Input Format:
First line will contain the string value S.
Second line will contain the value of A.
Third line will contain the value of B.
Output Format:
First line will contain the integer which represents the number of occurrences in sring S where A is followed by B

Sample Input/Output:
Example 1:
Input:
malayalam
a
l
Output:
2
Explanation:
The two occurrences where a is followed by l is as highlighted below.
Example 2:
Input:
engine
e
n
Output:
1

Max Execution Time Limit: 5000 millisecs


Difference between LCM and HCF of two numbers.

ID:211

Solved By 4175 Users

Two whole numbers N1 and N2 are passed as input. The program must print the difference between the LCM and
HCF of these two numbers.
Input Format:
First line will contain the value of the first number N1
Second line will contain the value of the second number N2
Output Format:
First line will contain the difference between the LCM and HCF of N1 and N2
Boundary Conditions:
1 <= N1 <= 99999
1 <= N2 <= 99999
Sample Input/Output:
Example 1:
Input:
30
45
Output:
75
Explanation:
LCM is 90 and HCF is 15. Difference = 90-15 = 75
Example 2:
Input:
100
120
Output:
580
Explanation:
LCM is 600 and HCF is 20. Difference = 600-20 = 580

Max Execution Time Limit: 5000 millisecs


Most Fuel Efficient car
ID:228

Solved By 4011 Users

Given fuel consumed and the distance covered for a certain number of cars, find the most fuel efficient car.
Input Format:
First line will contain the number N representing the number of cars.
Next N lines will contain the fuel consumed in liters and the distance run in kilometers (both separated by a space).
Output Format:
The number of the car which is most fuel efficient.
Sample Input/Output:
Example 1:
Input:
3
10 300
20 550
15 460
Output:
3
Explanation:
Average mileage of car 1 = 300/10 = 30 km/liter, car 2 = 550/20 = 27.5 km/liter, car 3 = 460/15 = 30.67 km/liter
Hence car 3 is most fuel efficient and hence 3 is printed.

Example 2:
Input:
5
10 200
20 400
10 210
20 430
15 250
Output:
4
Explanation:
Car 4 having 430/20 = 21.5 km/liter is the most efficient.

Max Execution Time Limit: 5000 millisecs


Maximum Repeating Count

ID:229

Solved By 3907 Users

Given an array of integers of length N, the program must find the value which repeats in maximum number of
times and print the number. In case of ties, choose the smaller number and print it.
Boundary Conditions:
Length of array N will be from 2 to 100
Input Format:
First line will contain the array of integers of length N separated by one or more spaces.
Output Format:
The integer value which repeats the maximum number of times.

Sample Input/Output:
Example 1:
Input:
10 20 30 20 30 10 30 20
Output:
20
Explanation:
Both 20 and 30 repeats three times. But 20 is the smaller number and hence 20 is printed as output.

Example 2:
Input:
123592969
Output:
9
Explanation:
9 repeats thrice which is more than the repetition count of any other number.

Max Execution Time Limit: 5000 millisecs


Country Capital

ID:238

Solved By 3815 Users

Input data containing N countries and their capital will be provided as input. The program must then print the
capital for a given country.
Input Format:
First line will contain the integer value N representing how many country-capital pairs are to be provided as input.
Next N lines will contain the name of the country and the name of the captial as string values separated by a
space.
The last line will contain the name of the country as a string value for which the capital is to be printed as output.
Output Format:
First line will contain the capital of the country. If the name of the country is NOT found in the input data then
NONE must be printed as output.
Constraints:
N will be from 2 to 100.
Sample Input/Output:
Example 1:
Input:
5
Afghanistan Kabul
Austria Vienna
Armenia Yerevan
Chile Santiago
Croatia Zagreb
Austria
Output:
Vienna

Example 2:
Input:
4
Armenia Yerevan
Chile Santiago
Croatia Zagreb
Iran Tehran
Japan
Output:
NONE
Explanation:
As Japan is not mentioned in the input data, NONE is printed as output.

Max Execution Time Limit: 5000 millisecs


Count of common characters in two strings

ID:210

Solved By 5134 Users

Two string values S1 and S2 are passed as input. The program must print the count of common characters in the
strings S1 and S2.
Input Format:
First line will contain the value of string S1
Second line will contain the value of string S2
Output Format:
First line will contain the count of common characters.
Boundary Conditions:
Length of S1 and S2 is from 3 to 100.
Sample Input/Output:
Example 1:
Input:
china
india
Output:
3
Explanation:
The common characters are i,n,a

Example 2:
Input:
energy
every
Output:
4
Explanation:
The common characters are e,e,r,y

Max Execution Time Limit: 5000 millisecs


Adding reversed numbers

ID:220

Solved By 4740 Users

A pair of numbers (X and Y) will be passed as input. The program must reverse the numbers and find the sum S.
Then the sum S must be reversed and printed as output.
- If any leading zeroes are obtained while reversing any of the numerical values they should be discarded.

Boundary Conditions:
0 < X < 10000
0 < Y < 10000

Input Format:
First line will contain the value of X
Second line will contain the value of Y
Output Format:
The first line will contain the sum S

Sample Input/Output:
Example 1:
Input:
24
1
Output:
34
Explanation:
24 when reversed is 42. So 42+1 = 43.
When 43 is reversed it is 34 and hence 34 is the output.
Example 2:
Input:
305
794
Output:
1
Explanation:
305 and 794 when reversed are 503 and 497.
503+497 = 1000.
1000 when reversed is 1 which is printed as output.

Max Execution Time Limit: 5000 millisecs


Toggle Case

ID:235

Solved By 4556 Users

Simon wishes to convert lower case alphabets to upper case and vice versa. Help Simon by writing a program
which will accept a string value S as input and toggle the case of the alphabets.
Numbers and special characters remain unchanged.
Input Format:
First line will contain the string value S
Output Format:
First line will contain the string value with the case of the alphabets toggled.
Constraints:
Length of S is from 2 to 100
Sample Input/Output:
Example 1:
Input:
GooD mORniNg12_3
Output:
gOOd MorNInG12_3

Example 2:
Input:
R@1nBow
Output:
r@1NbOW

Max Execution Time Limit: 5000 millisecs


Matrix Diagonals Sum

ID:2666

Solved By 4258 Users


You are given a square matrix of size N×N. Calculate the sum of the integers present in the two main diagonals.
Input Format:
The first line will contain the value of N.
The next N lines will contain the N values separated by one or more spaces.
Output Format:
The sum of the integers present in the two main diagonals.
Boundary Conditions:
2 <= N <= 20
Example Input/Output 1:
Input:
2
10 9
4 22
Output:
45
Explanation:
The sum is = 10+22+9+4 = 45
Example Input/Output 2:
Input:
3
5 10 11
79 6 12
9 21 45
Output:
76
Explanation:
The sum is = 5+6+45+11+9 = 76.
As 6 is common for both the diagonals it must be counted only once when finding the sum.

Max Execution Time Limit: 5000 millisecs


Arrange the alphabets in a string in descending order

ID:2

Solved By 4230 Users

A string (with only alphabets) S is passed as input. The program should print the alphabets in the string in
descending order. Assume all alphabets will be in lower case.
Boundary Conditions:
The length of string S is between 2 and 100.
Example input and output:
If the input is "cake", the output should be "keca"
If the input is "innovation", the output should be "vtonia" (n or o or i should not be repeated)
Max Execution Time Limit: 5000 millisecs
Absolute difference of the sum across the diagonals

ID:424

Solved By 3862 Users

You are given a square matrix of size N×N. Calculate the absolute difference of the sums across the two main
diagonals.
Input Format:
The first line will contain the value of N.
The next N lines will contain the N values separated by one or more spaces.
Output Format:
The absolute difference of the sums across the two main diagonals.
Boundary Conditions:
2 <= N <= 20
Example Input/Output 1:
Input:
2
10 9
4 22
Output:
19
Explanation:
The sum along the first diagonal is 10+22 = 32
The sum along the first diagonal is 4+9=13
The absolute difference is 32-13= 19
Example Input/Output 2:
Input:
2
-10 6
4 -22
Output:
22

Max Execution Time Limit: 5000 millisecs


Festive discount

ID:218

Solved By 3809 Users

In a shop, discounts were provided as below.


- If the label price of an item is more than Rs.400, then the discount is 20%.
- If the label price of an item is more than Rs.500, then the discount is 25%.
- If the label price of an item was more than or equal to Rs.1000, then the discount is 50%.
- Finally if the total purchase amount after discount is more than Rs.2000 a further discount of Rs.100 is provided.
The label prices of the items purchased will be provided as input. The program has to calculate the final price
payable by the buyer (customer).
Boundary Conditions:
Number of items bought will be from 1 to 20.
Input Format:
First line will contain the number of items (N)
Next N lines will contain the label price of N items.
Output Format:
The final price payable by the buyer rounded off to two decimal places.
Sample Input/Output:
Example 1:
Input:
3
1000
1200
400
Output:
1500.00
Explanation:
1000,1200,400 after discount becomes 500,600,400 (20% discount is applicable only if the label price is more
than Rs.400)
Hence net payable amount = 500+600+400 = 1500

Example 2:
Input:
5
450
500
2000
1600
300
Output:
2760.00
Explanation:
After discount the selling price of items are 360,400,1000,800,300. Net amount = 2860.
As 2860 > 2000, a further discount of 100 is provided and hence output is 2760.00

Max Execution Time Limit: 5000 millisecs


String - Letters comparison

ID:207

Solved By 3785 Users


Two string values S1 and S2 are passed as input. The program must check if both S1 and S2 contain the same
unique set of letters and print YES or NO. Assume all the letters (alphabets) are in smaller case.
Boundary Conditions:
Length of S1 is from 2 to 100
Length of S2 is from 2 to 100
Input Format:
First line will contain the string value of S1
Second line will contain the string value of S2
Output Format:
YES or NO depending on if both S1 and S2 contain the same set of unique letters.
IMPORTANT:
Please note that the output is CASE SENSITIVE. Hence print YES or NO (instead of yes or no)

Sample Input/Output:
Example 1:
Input:
read
dear
Output:
YES
Explanation:
Both S1 and S2 are formed using the letters - a d e r

Example 2:
Input:
record
decoder
Output:
YES
Explanation:
Both S1 and S2 are formed using the letters - c d e o r

Example 3:
Input:
energy
synergy
Output:
NO
Explanation:
S2 has additional letters - s y in it.

Max Execution Time Limit: 5000 millisecs


Print the day for a given date.

ID:213

Solved By 3430 Users


The day corresponding to the first date of a given month is provided as input to the program. Then a specific
date D of the month is provided. The program must print the day (one among MON,TUE, WED, THU, FRI, SAT,
SUN) of the date D.
Input Format:
First line will contain the day (one among MON,TUE, WED, THU, FRI, SAT, SUN) of the first date of the month.
Second line will contain the value of the date D as an integer value.
Output Format:
First line will contain the day of the date D

Sample Input/Output:
Example 1:
Input:
MON
10
Output:
WED
Explanation:
If it is Monday on 1st of the month, then 10th of the month will be a Wednesday. Hence WED is printed.

Example 2:
Input:
FRI
24
Output:
SUN
Explanation:
If it is Friday on 1st of the month, then 22nd will also be a Friday. Hence 24th of the month will be a Sunday. Hence
SUN is printed.

Max Execution Time Limit: 5000 millisecs


Cricket player with higher average

ID:205

Solved By 3383 Users

The runs scored by two cricket players is passed as input. The program must print the total runs scored by the
better player.
The better player is the player with a higher average. It is not necessary that both the players have played/scored
in the same number of matches.
If both the players have same average, then print the runs scored by the player who has the highest total runs.
Boundary Conditions:
- The number of matches played for any player will not exceed 20.
- If a negative value is passed as runs scored, then the program output must be INVALIDINPUT.
Input Format:
First line will contain the runs scored by player one. The scores are separated by one or more spaces.
Second line will contain the runs scored by player two. The scores are separated by one or more spaces.
Output Format:
The first line will contain the total runs scored by the player having higher average.

Sample Input/Output:
Example 1:
Input:
20 30 40
50 10
Output:
90
Explanation:
Both the players have same average 30. Hence the output is the highest total runs which is by player 1. (20+30+40
= 90)

Example 2:
Input:
50 60 10
50 40
Output:
90

Example 3:
Input:
40 42 60
0 100 56
Output:
156
Example 4:
Input:
42 -10
22 45
Output:
INVALIDINPUT
Explanation:
As -10 is passed as runs scored in the input, the program must print INVALIDINPUT

Max Execution Time Limit: 5000 millisecs


Pattern Printing - Numbers [ZOHO]

ID:2670

Solved By 5275 Users

Based on the input value of N, the program must print the pattern described below.
Input Format:
First line will contain the value of N.
Output Format:
N lines will contain the number pattern as described below with each value separated by a single space.
Boundary Conditions:
1 <= N <= 50
Example Input/Output 1:
Input:
5
Output:
1 6 10 13 15
2 7 11 14
3 8 12
49
5
Example Input/Output 2:
Input:
3
Output:
146
25
3

Max Execution Time Limit: 5000 millisecs


Sum of proper divisors

ID:223

Solved By 4836 Users

Given a natural number N , the program must print the sum of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.
Boundary Conditions:
1 < N <= 100000
Input Format:
First line will contain the integer value of N.
Output Format:
First line will contain the sum of all the proper divisors of N.

Sample Input/Output:
Example 1:
Input:
2
Output:
1
Explanation:
1 is the only proper divisor of 2. Hence sum is also 1.

Example 2:
Input:
20
Output:
22
Explanation:
The proper divisors of 20 are 1,2,4,5,10. Hence their sum is 22

Max Execution Time Limit: 5000 millisecs


Reverse Pattern Printing - Numbers

ID:2671

Solved By 4357 Users

Based on the input value of N, the program must print the pattern described below.
Input Format:
First line will contain the value of N.
Output Format:
N lines will contain the number pattern as described below with each value separated by a single space.
Boundary Conditions:
1 <= N <= 50
Example Input/Output 1:
Input:
5
Output:
15 10 6 3 1
14 9 5 2
13 8 4
12 7
11
Example Input/Output 2:
Input:
3
Output:
631
52
4

Max Execution Time Limit: 5000 millisecs


Identify correct operator.

ID:227
Solved By 4309 Users

An expression E is passed as an input to the program. The expression will contain three numbers A, B and C, one
equal symbol and one of the mathematical operators + - * /
But the given mathematical operator is incorrect and hence the expression is not valid. Hence the program must
identify the correct operator and print that as the output.

Input Format:
First line will contain the expression E
Output Format:
First line will contain the correct mathematical operator

Sample Input/Output:
Example 1:
Input:
5-4=20
Output:
*
Explanation:
Only 5 multiplied with 4 gives 20. Hence - must be replaced with *.

Example 2:
Input:
999+9=111
Output:
/
Explanation:
Only 999 divided by 9 gives 111. Hence + must be replaced with /.

Max Execution Time Limit: 5000 millisecs


Rotate Matrix 90 Degree Anti-Clockwise

ID:2669

Solved By 4150 Users

A MxN matrix is passed as the input. The program must rotate the matrix by 90 degrees in anti-clock wise
direction and print the rotated matrix as the output.
Input Format:
First line will contain the value of M.
Second line will contain the value of N.
Next M lines will contain the N values with each value separated by one or more space.
Output Format:
N lines will contain the M values with each value separated by one or more space.
Boundary Conditions:
2 <= M <= 15
2 <= N <= 15
Example Input/Output 1:
Input:
2
3
459
135
Output:
95
53
41
Example Input/Output 2:
Input:
4
4
1234
5678
9 10 11 12
13 14 15 16
Output:
4 8 12 16
3 7 11 15
2 6 10 14
1 5 9 13

Max Execution Time Limit: 5000 millisecs


Add Numbers - Base N

ID:2672

Solved By 3866 Users

Two numbers X and Y are provided with reference to base N. Add the numbers and print their sum with reference
to base 10.
Input Format:
First line will contain the value of N.
Second line will contain X and Y separated by one or more spaces.
Output Format:
First line will contain the sum of X and Y to the base 10.
Boundary Conditions:
1 <= N <= 10
Example Input/Output 1:
Input:
2
1010 11
Output:
13
Explanation:
1010 to the base 2 is 10. 11 to the base 2 is 3.
Hence the sum is 10+3 = 13.
Example Input/Output 2:
Input:
3
11 201
Output:
23
Explanation:
11 to the base 3 is 4. 201 to the base 3 is 19.
Hence the sum is 23

Max Execution Time Limit: 5000 millisecs


Rotate Matrix 90 Degree Clockwise

ID:2668

Solved By 3827 Users

A MxN matrix is passed as the input. The program must rotate the matrix by 90 degrees in clock wise direction
and print the rotated matrix as the output.
Input Format:
First line will contain the value of M.
Second line will contain the value of N.
Next M lines will contain the N values with each value separated by one or more space.
Output Format:
N lines will contain the M values with each value separated by one or more space.
Boundary Conditions:
2 <= M <= 15
2 <= N <= 15
Example Input/Output 1:
Input:
2
3
459
135
Output:
14
35
59
Example Input/Output 2:
Input:
4
4
1234
5678
9 10 11 12
13 14 15 16
Output:
13 9 5 1
14 10 6 2
15 11 7 3
16 12 8 4

Max Execution Time Limit: 5000 millisecs


Smaller Matrix Search [ZOHO]

ID:2667

Solved By 3217 Users

A bigger NxN matrix is passed as the input. Also a smaller MxM matrix is passed as input. The program must print
TRUE if the smaller matrix can be found in the bigger matrix. Else the program must print FALSE.
Input Format:
First line will contain the value of N.
Second line will contain the value of M.
Next N lines will contain the values in the N*N matrix with each value separated by one or more space.
Next M lines will contain the values in the M*M matrix with each value separated by one or more space.
Output Format:
First line will contain the string value TRUE or FALSE
Boundary Conditions:
3 <= N <= 20
2 <= M <= N
Example Input/Output 1:
Input:
3
2
459
135
824
35
24
Output:
TRUE
Example Input/Output 2:
Input:
3
2
459
135
824
45
14
Output:
FALSE
Max Execution Time Limit: 5000 millisecs
Robot co-ordinates

ID:6

Solved By 3142 Users

The initial x and y co-ordinate values of a Robot are passed as the input.
The rest of the input values are the directions in which the Robot moves along with the distance in that direction.
The directions are denoted by N, E, S, W for North, East, South and West.
The program should print the final x and y co-ordinates of the Robot.
The input will be a single string value with the above details separated by one or more spaces.
Boundary Conditions:
The length of the input string will be less than 100.
Example Input/Output:
If the input string is x2 y1 N3 E2 S1 the output must be x4 y3
If the input string is x-2 y3 N1 W3 the output must be x-5 y4

Max Execution Time Limit: 5000 millisecs


Next Greater Number - Same Digits

ID:2673

Solved By 3088 Users

A number N is passed as the input. The program must print the next greater number with the same digits.
Input Format:
First line will contain the value of N.
Output Format:
First line will contain the next greater number with the same digits.
Boundary Conditions:
1 <= N <= 99999999999999
Example Input/Output 1:
Input:
12
Output:
21
Example Input/Output 2:
Input:
195
Output:
519

Max Execution Time Limit: 5000 millisecs

You might also like