Python Average Challenges
Python Average Challenges
ID:2615
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
ID:2613
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
ID:2621
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
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
ID:2618
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
ID:2617
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
ID:2619
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
ID:2620
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
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
ID:2617
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
ID:2619
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
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
ID:242
Example 2:
Input:
credit 1 lakh
3
0
Output:
fuhglw 1 odnk
ID:221
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
ID:209
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
ID:215
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.
ID:2622
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.
ID:2624
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
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.
ID:2623
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
ID:237
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.
ID:219
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.
ID:243
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
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.
ID:214
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
ID:204
ID:226
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
ID:225
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
ID:211
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
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.
ID:229
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.
ID:238
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.
ID:210
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
ID:220
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.
ID:235
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
ID:2666
ID:2
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
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
ID:218
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
ID:207
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.
ID:213
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.
ID:205
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
ID:2670
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
ID:223
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
ID:2671
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
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 /.
ID:2669
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
ID:2672
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
ID:2668
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
ID:2667
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
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
ID:2673
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