64% found this document useful (11 votes)
10K views34 pages

InfyTQ Coding Questions Set 2 PDF

The headmaster of ABS School wants to improve their SSLC results next year. They will provide free SSLC coaching to students who passed the 5th standard final exam. The education department needs to identify these students from the 5th standard results. They have marks of N students in 6 subjects. Write a program to find the total marks and average of each student, and identify students who passed with a minimum average of 35%.

Uploaded by

Walker Sanket
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
64% found this document useful (11 votes)
10K views34 pages

InfyTQ Coding Questions Set 2 PDF

The headmaster of ABS School wants to improve their SSLC results next year. They will provide free SSLC coaching to students who passed the 5th standard final exam. The education department needs to identify these students from the 5th standard results. They have marks of N students in 6 subjects. Write a program to find the total marks and average of each student, and identify students who passed with a minimum average of 35%.

Uploaded by

Walker Sanket
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
You are on page 1/ 34

1) Adjacent Stick Game

Mukesh and friends have set out on a vacation to Coorg. They have booked
accommodation in a resort and the resort authorities organize Campfires every
night as a part of their daily activities. Mukesh volunteered himself for an activity called the
“Adjacent Stick Game" where sticks of different lengths will be placed in a line and Mukesh
needs to remove a stick from each adjacent pair of sticks. He then has to form a bigger stick
by combining all the remaining sticks.
Mukesh needs to know the smallest length of the bigger stick so formed and needs your help
to compute the same. Given the number of sticks N and the lengths of each of the sticks,
write a program to find the smallest length of the bigger stick that is formed.

Input Format
First line of input contains an integer N denoting the number of sticks. Assume that the
maximum value for N as 50.
Assume that N is always even.
Next line of input contains an N integer denoting the length of each of the sticks.
Output Format
Output the smallest length of the bigger stick that is formed.
Refer to sample input and output for formatting specifications.
Sample Testcases
Testcase 1 Input Testcase 1 Output
4 5
4235

Testcase 2 Input Testcase 2 Output


4 2
2131

Video Solution Link: https://youtu.be/qjIiQq_Zfvg


2) Airline Client Details
Airport check-in uses service counters found at commercial airports handling
commercial air travel. The check-in is normally handled by an airline itself or a
handling agent working on behalf of an airline. At the time of check-in, one of the Agent's
primary duties is to check for client details, tickets, passports, visas, letters of consent etc.
Client details are stored in a Dictionary.
The passport number is the key and client details are the value. Write a program to get the
value(Client details) by giving the key(passport number) from the dictionary.

Input Format
Input consists of an integer that represents the person.
Second line of input contains the details

Output Format
output displays the information
Sample Testcases
Testcase 1 Input Testcase 1 Output
2 Client not found
shri
shri@mail.com
7346218
veena
veena@gmail.com
8639124
12354545

Testcase 2 Input Testcase 2 Output


2 Veena- -veena@mail. com- -8639124
shri
shri@mail.com
7346218
veena
veena@mail.com
8639124
8639124
Video Solution Link: https://youtu.be/PoaWGJ0ywhg

This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
3) Best Couple Event
"Shades" Television Channel organizes a fun-filled event named “Best Couple
2017", were in married couples would be invited and given many tasks and
activities. Based on some criteria decided by the jury, the best couple will be chosen.
N couples registered for the event and each couple was given a registration number(it may
repeat). One specific couple's registration Id got missed. The event coordinators wanted
your help in finding the missing Id.
Write a program which takes an array of registration numbers as input and outputs the
missing registration Id.
Input Format
First line of the input contains the number of couples N who registered for the event.
Assume that the maximum value for N as 50.
Second line of input contains N registration Id of each of the couple, separated by a space.
Output Format
Output in a single line the missing registration Id.
Refer to sample input and output for formatting specifications.
Sample Testcases
Testcase 1 Input Testcase 1 Output
5 3
11223

Testcase 2 Input Testcase 2 Output


3 2
121

Video Solution Link : https://youtu.be/CGCMhwpW5pE


4) Competitive Test
“Axcent Academy” has arranged for a competitive test for medical students from
rural villages. Those successful students of the test will be awarded the scholarship
for their NEET preparations at Axcent Academy. Benny, the co-coordinator and founder of the
academy has given one problem for the first stage of the test. The problem goes like this:
Given an array A1, A2, ..., AN, count the number of sub-arrays of array A which are non-
decreasing.
A sub-array A[i, j], where 1 ≤ i ≤ j <WN is a sequence of integers Ai, Ai+1, ..., Aj.
A sub-array A[i, j] is non-decreasing if Ai ≤ Ai+1 ≤ Ai+2 ≤ ... ≤ Aj. Count the total number of
such sub-arrays.
Benny himself has not computed the solution to the problem. Write a program to help him
find the answer for the same to evaluate the students.
Input Format
The first line of input contains a single integer N denoting the size of an array. Assume that the
maximum value for N as 50.
The second line contains N space-separated integers A1, A2, ...AN denoting the elements of
the array.
Output Format
Output in a single line, the count of the total number of such sub-arrays.
Refer to sample input and output for formatting specifications.
Sample Testcases
Testcase 1 Input Testcase 1 Output
3 4
314

Testcase 2 Input Testcase 2 Output


4 6
1423

Video Solution Link : https://youtu.be/c5aEUpx3iOE


5) Friendship Test
Michael is celebrating his 10th birthday and he wished to arrange a party to all
his classmates. But there are n tough guys amongst his class who are weird. They
thought that this is the best occasion for testing their friendship with him. They put up
conditions before Michael that they will break the friendship unless he gives them a grand
party on their chosen day. Formally, ith friend will break his friendship if he does not receive
a grand party on dith day.
Michael is not a lavish spender and can give at most one grand party daily. Also, he wants to
invite only one person in a party. So he just wonders what the maximum number of
friendships he can save.
Please help Michael with this difficult task.
Input Format
First-line will contain a single integer denoting n. Assume that the maximum value for n as
50.
Second-line will contain n space-separated integers where ith integer corresponds to the day
dith as given in the problem.
Output Format
Print a single line corresponding to the maximum number of friendships
Michael can save.
Refer to sample input and output for formatting specifications.
Sample Testcases
Testcase 1 Input Testcase 1 Output
5 4
41335

Testcase 2 Input Testcase 2 Output


2 2
32

Video Solution Link : https://youtu.be/jVcKbASgiOs


6) List of Orders
List of orders from amazon are given along with the departure date. The Amazon
are adding features to their delivery management system in iterations. The Support
desk is finding it difficult to filter the Trains with the departure dates from the data available.
Can you please implement a date filter to help the Support desk with this regard?
Input Format
The first line of input is an integer that corresponds to the number of records, ‘n’.
The next 'n' line corresponds to the records.
The last line of input consists of the date to be filtered.
Output Format
The first line of the output is a set of comma-separated string containing the cargo name and
date.
The next lines consist of the names of the cargo printed one next to others separated by a
new line.
Sample Testcases
Testcase 1 Input Testcase 1 Output
5 [('Sparx_Shoes', '11-12-2013‘), (‘Suits', ‘29-12-2016'),
Sparx_Shoes, 11-12-2013 (‘SAMSUNG Mobiles’), ('SAMSUNG Mobiles’, '27-03-
suits,29-12-2016 2017'), (‘Tissot Watchs', ‘10-04-2014'), (‘Levis Denim’,
SAMSUNG Mobiles, 27-03-2617 ’7-03-2017'), (‘Tissot Watchs', '10-04-2014'), ('Levis
Tissot watchs, 10-04-2014 Denim', ‘27-03-2017')]
Levis Denim, 27-03-2017 suits
27-03-2816 SAMSUNG Mobiles
Levis Denim

Video Solution Link : https://youtu.be/BMHOwV_OPz0


7) Lucy at the Film Festival
LucarnosFilm Festival is an annual film festival and is also known for being a
prestigious platform for art house films. This time at the Lucarnos Film festival
there are N movies screened, each of different genres ranging from drama movies
to comedy ones and teen movies to horror ones. Lucy is a huge fan of movies and visited the
film festival, but she’s not sure which movie she should watch.
Each movie can be characterized by two integers Li and Ri, denoting the length and the
rating of the corresponding movie. Lucy wants to watch exactly one movie with the maximal
value of Li x Ri. If there are several such movies, she would pick a one with the maximal Ri
among them. If there is still a tie, she would pick the one with the minimal index among
them.
Write a program to help Lucy pick a movie to watch at the film festival.
Input Format
The first line of the input description contains an integer n. Assume that the maximum value
for n as 50.
The second line of the input description contains n integers L1, L2, ..., Ln.
The following line contains n integers R1, R2, ..., Rn.
Output Format
Output a single integer i denoting the index of the movie that Lucy should
watch in the film festival. Note that you follow 1-
based indexing.
Refer to sample input and output for formatting specifications.
Sample Testcases
Testcase 1 Input Testcase 1 Output
4 2
2141
2414

Testcase 2 Input Testcase 2 Output


2 1
12
21

Video Solution Link : https://youtu.be/8HJr3TPOQ1E


8) Students Results
ABS School wants good SSLC results in the next upcoming year. So they wanted to
prepare students who passed the Sth standard final exam.The education
department of the school decided to give free SSLC coaching to students. Headmaster told
the class teacher to shortlist the students who passed and failed in final exam of 9th
standard. Now she wants to create new students list who passed and failed the final exam.
Help her to create new student lists. If the student mark is less than 40 then he is failed
otherwise he is passed.
Input Format
1st input indicates a number of students.
Next lines of input indicate marks of students(Marks entered according to Roll No, Roll No
starts from 1).
Output Format
The output indicates Roll No of students who failed and passed (Refer sample input-output
format).
All text in bold corresponds to the input and the rest corresponds to output.
Sample Testcases
Testcase 1 Input Testcase 1 Output
6 All are passed
41
67
45
80
89
67

Testcase 2 Input Testcase 2 Output


5 5 Students who failed in Final Exam
78 78 Roll No: 2
39 39 Roll No: 4
45 45 Students who passed in Final Exam
35 35 Roll No: 1
89 89 Roll No: 3
Roll No: 5
Testcase 3 Input Testcase 3 Output
5 All are failed
23
24
28
26
27

Video Solution Link : https://youtu.be/dZSg5PU6WT0


9) A person saves his monthly savings according to given schema. He saves same
amount of money which is equal to the money saved in immediate previous two
months. Assume, initially, he saved 1000 rupees and in the first month he saved
another 1000. Your task is to tell how much he had totally saved at the end of ‘n’ months
Input Format
You will be given a number 'n’->No. of months.
Output Format
Print the total savings at the end of ‘n’ months.
Sample Testcases
Testcase 1 Input Testcase 1 Output
1 2000

Testcase 2 Input Testcase 2 Output


3 7000

Video Solution Link: https://youtu.be/WtPHYA_Zv5M


10) Given a list of numbers in Python List, write a Python program to create a
list of tuples having the first element as the number and second element as
the cube of the number.
Input Format
Input contains integers separated by spaces.
Output Format
Output displays in the form of list of tuples.
Sample Testcases
Testcase 1 Input Testcase 1 Output
12345 [(1, 1), (2, 8), (3, 27), (4, 64), (5, 125)]

Video Solution Link : https://youtu.be/IV-5W1cdPRg


11) Given a number N an array of N numbers. The task is to find all the star and
super star elements in the array an print in a seperate line.Star are those elements
which are strictly greater than all the elements on its right side. Super star are
those elements which are strictly greater than all the elements on its left and right
side.Assume first element (A[0]) is greater than all the elements on its left side,
And last element (A[n-1]) is greater than all the elements on its right side.
Input Size : 1 <= N <= 100000

Input Format
First line contains a number of elements N in an array [>
Second line contains N elements separated by spaces

Output Format
First line of output displays numbers representing Star elements separated by
spaces
Second line of output displays numbers representing Super Star elements
separated by spaces
Sample Testcases
Testcase 1 input Testcase 1 Output

6 721
346721 7

Video Solution Link : https://youtu.be/IgF17TqdGfI

This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
12) Given a number N, print the odd digits in the number(space separated) or
print -1 if there is no odd digit in the given number.
Input Size : N <= 100000.
Input Format
Input consists of an integer.
Output Format
Output displays the odd digits if there are any, If not it displays -1.
Sample Testcases
Testcase 1 Input Testcase 1 Output
2143 13

Testcase 2 Input Testcase 2 Output


2468 -1

Video Solution Link : https://youtu.be/teBQZHnzoh8


13) Given the base and height of a triangle find the area. Note: The base and height of a
triangle should accommodate float value as well.
Input Format
Input contains two space-separated values representing the base and height of a triangle.
Output Format
Output displays area of a triangle
Sample Testcases
Testcase 1 Input Testcase 1 Output
24 4.0

Testcase 2 Input Testcase 2 Output


12.5 7 43.75

Video Solution Link : https://youtu.be/EF1yoZfUfjo


14) Given the list of dictionaries with key as ‘Name’.
Write a python program to sort the list of dictionaries by Name(sorted in
ascending order)
Input Format
First line contains the number of dictionaries N
N line contains values of the dictionary (i.e.,) Name
Refer sample input for better understanding
Output Format
Output displays the list of dictionaries sorted in ascending order of name.
Refer sample output for better understanding
Sample Testcases
Testcase 1 input Testcase 1 Output

4 ({'Name': 'Alice'}, {‘Name’: ‘Bharath’}, {‘Name’: ‘Moana'},


Ramu {‘Name‘: 'Ramu'}, {'Name‘: 'Alice'}, {‘Name’: ‘Bharath’},
Alice {‘Name’: ‘Moana'}, {‘Name‘: 'Ramu’}]
Moana
Bharath
Video Solution Link : https://youtu.be/0qybLh1aSIA

This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
15) Pk finds it difficult to judge the minimum element in the list of elements given to him.
Your task is to develop the algorithm in order to find the minimum element.
Note: Don't use sorting
Input Format
You are given ‘n’ number of elements. The next line contains n space-separated numbers.
Output Format
Print the minimum element
Sample Testcases
Testcase 1 Input Testcase 1 Output
5 1
34916

Video Solution Link: https://youtu.be/SUC98blM9Y0


16) Raja and his friends want to add all their subject marks from internal exams.
Can you help them by writing python code to find the sum of their marks using
the List concept.
Input Format
Input contains marks separated by spaces
Output Format
Output contains a number representing the total sum
Sample Testcases
Testcase 1 Input Testcase 1 Output
40 42 50 10 8 150

Video Solution Link: https://youtu.be/JJz6c9lLAgc


17) Rajesh was going through alternative array sorting. He wishes to print the
array alternatively. Hence hired you. Your task is to help Rajesh in printing the
array alternatively.
An alternative array is an array in which first element is maximum of the whole
array second element is minimum of the whole array. Third element is second
largest. Fourth element is second smallest. And so on...
Input Format
You are given the length of the array ‘n’. Next line contains ‘n’ space-separated
numbers.
Output Format
Print the array as mentioned.
Sample Testcases
Testcase 1 Input Testcase 1 Output
5 19 1 16 7 11
1 7 11 16 19

Video Solution Link: https://youtu.be/AOZ7uso7uL4


18) Sensex has never been steady and stock values have been rising and falling in
the past. Ram is a stockbroker and on analyzing the trend of change in Sensex
points, he decides that there was a period when the points was at its all time high
and investing during that period would have earned him a huge profit in trade. Ram
immediately regrets not having done any trade in that particular period. Find out which
period in time was Ram referring to.
Input Format
First-line contains integer N representing number of periods
Second-line contains space-separated N integers representing Sensex points
Output Format
Output displays a period in which the points were at its max value. The array index is the
period value.
Sample Testcases
Testcase 1 Input Testcase 1 Output
10 3
10 25 25 45 42 26 17 12 11 12

Video Solution Link : https://youtu.be/QBdeguq4zPg


19) Shapur has to find weaknesses in the roman army to defeat them. So he
gives the army a weak number. In Shapur's opinion the weakness of an army is
equal to the number of triplets i, j, k such that i<j <k and ai > aj > ak where ax is the
power of man standing at position x. The Roman army has one special trait — the powers
of all the people in it are distinct. Help Shapur find out how weak the Romans are.
Input Size : N<=100000.
Input Format
Input consists of n+1 integers.
First line of the input consists of size 'n' of the integer array,
Followed by n number of space-separated integer inputs.
Output Format
Output displays the weakness number as defined by the problem statement.
Sample Testcases
Testcase 1 Input Testcase 1 Output
8 4
987654
Testcase 2 Input Testcase 2 Output
3 1
321

Video Solution Link : https://youtu.be/46fWg6xQwqI


20) Write a program to get two lists of integers from the user and create a third
list such that should contain only odd numbers from the first list and even
numbers from the second list.
Input Format
Number of elements in first list
Number of elements in second list
First list elements
Second list elements
Output Format
First list
Second list
Third list as per requirement
Sample Testcases
Testcase 1 Input Testcase 1 Output
3 [12, 34, 45]
5 [88, 23, 43, 33, 56]
12 [12, 34, 23, 43, 33]
34
45
88
23
43
33
56

Video Solution Link : https://youtu.be/zps2ZHeIcvk

You might also like