# InfyTQ Coding Questions 2023

## InfyTQ Coding Questions and Solutions

Infosys is conducting its Infosys Competition test through InfyTQ. Here you will get various different coding rounds, out of which the InfyTQ Coding Questions and Solutions round is the easiest one. As you move ahead you get questions of more higher difficulty.

## InfyTQ Coding Round Details

Topics No. of Questions
Number of Questions 3-5
Time Limit variable
Difficulty level high
Package Offered 3.6 LPA – 8 LPA

## InfyTQ Practice Coding Questions and Solutions

### Question 1: Biggest Meatball

Problem Statement – Bhojon is a restaurant company and has started a new wing in a city. They have every type of cook except the meatball artist. They had fired their last cook because the sale of meatballs in their restaurant is really great, and they can’t afford to make meatballs again and again every time their stock gets empty. They have arranged a hiring program, where you can apply with their meatball.
They will add the meatball in their seekh (a queue) and everytime they cut the meatball they take it and cut it on the day’s quantity and then re-add the meatball in the seekh. You are the hiring manager there and you are going to say who is gonna be hired.

Day’s quantity means, on that very day the company sells only that kg of meatballs to every packet.

If someone has less than a day’s quantity, it will be counted as a sell.

Function Description:

• Complete the function with the following parameters:

Parameters:

NameTypeDescription
NIntegerHow many people are participating in the hiring process.
DIntegerDay’s quantity, how many grams of meatball is being sold    to every packet.
Array[ ]Integer arrayArray of integers, the weight of meatballs everyone came with.

Return:

• The ith person whose meat is served at last.

Constraints:

• 1 <= N <= 10^3
• 1 <= D <= 10^3
• 1 <= Array[i] <= 10^3

Input Format:

• First line contains N.
• Second line contains D.
• After that N lines contain The ith person’s meatball weight.

Output Format: The 1 based index of the man whose meatball is served at the last.

Sample Input 1:

4

2

[7 8 9 3]

Sample Output 1:

3

Explanation:

The seekh or meatball queue has [7 8 9 3] this distribution. At the first serving they will cut 2 kgs of meatball from the first meatball and add it to the last of the seekh, so after 1st time it is:

[8 9 3 5]

Then, it is: [9 3 5 6],  [3 5 6 7], [5 6 7 1], [6 7 1 3], [7 1 3 4], [1 3 4 5], [3 4 5], [4 5 1], [5 1 2], [1 2 3], [2 3], [3], [1], [0]

So the last served meatball belongs to the 3rd person.

### Question 2: Self Sufficient

Problem Statement –  Abhijeet is one of those students who tries to get his own money by part time jobs in various places to fill up the expenses for buying books. He is not placed in one place, so what he does, he tries to allocate how much the book he needs will cost, and then work to earn that much money only. He works and then buys the book respectively. Sometimes he gets more money than he needs so the money is saved for the next book. Sometimes he doesn’t. In that time, if he has stored money from previous books, he can afford it, otherwise he needs money from his parents.

Now His parents go to work and he can’t contact them amid a day. You are his friend, and you have to find how much money minimum he can borrow from his parents so that he can buy all the books.

He can Buy the book in any order.

Function Description:

Complete the function with the following parameters:

NameTypeDescription
NIntegerHow many Books he has to buy that day.
EarnArray[ ]Integer arrayArray of his earnings for the ith book
CostArray[ ]Integer arrayArray of the actual cost of the ith book.

Constraints:

• 1 <= N <= 10^3
• 1 <= EarnArray[i] <= 10^3
• 1 <=  CostArray[i] <= 10^3

Input Format:

• First line contains N.
• Second N lines contain The ith earning for the ith book.
• After that N lines contain The cost of the ith book.

Output Format: The minimum money he needs to cover the total expense.

Sample Input 1:

3

[3 4 2]

[5 3 4]

Sample Output 1:

3

Explanation:

At first he buys the 2nd book, which costs 3 rupees, so he saves 1 rupee. Then he buys the 1st book, that takes 2 rupees more. So he spends his stored 1 rupee and hence he needs 1 rupee more. Then he buys the last book.

### Question 3: Parallel Columbus

Problem Statement –  Nobel Prize-winning Austrian-Irish physicist Erwin Schrödinger developed a machine and brought as many Christopher Columbus from as many parallel universes he could. Actually he was quite amused by the fact that Columbus tried to find India and got America. He planned to dig it further.

Though totally for research purposes, he made a grid of size n X m, and planted some people of America in a position (x,y) [in 1 based indexing of the grid], and then planted you with some of your friends in the (n,m) position of the grid. Now he gathered all the Columbus in 1,1 positions and started a race.

Given the values for n, m, x, y, you have to tell how many different Columbus(s) together will explore you as India for the first time.

Remember, the Columbus who will reach to the people of America, will be thinking that as India and hence wont come further.

Function Description:

Complete the markgame function in the editor below. It has the following parameter(s):

Parameters:

NameTypeDescription
nIntegerThe number of rows in the grid.
mIntegerThe number of columns in the grid.
xIntegerThe American cell’s Row.
yIntegerThe American cell’s Column.

Constraints:

• 1 <= n <= 10^2
• 1 <= m <= 10^2
• 1 <= x <= n
• 1 <= y <= m

Input Format:

• The first line contains an integer, n, denoting the number of rows in the grid.
• The next line contains an integer m, denoting the number of columns in the grid.
• The next line contains an integer, x, denoting the American cell’s row.
• The next line contains an integer, y, denoting the American cell’s column.

Sample Cases

Sample Input 1

2

2

2

1

Sample Output 1

1

Explanation

The only way possible is (1,1) ->(2,1) -> (2,2), so the answer is 1.

### Question 4 Amusement park

Problem Statement – Aashay loves to go to WONDERLA , an amusement park. They are offering students who can code well with some discount. Our task is to reduce the cost of the ticket as low as possible.

The cost of tickets can be removed by removing the digits from the price given. They will give some k turns to remove the digits from the price of the ticket. Your task is to help Aashay in coding a program that can help him to reduce the cost of a ticket by removing the digits from its price and getting the maximum possible discount.

Note – You cannot make the cost of a ticket zero. For eg -: If the cost of a ticket is 100, and you have 2 turns to reduce the price, the final price will be 1 and not zero.

Constraints:

• 1 <= number of tickets <= 10^5
• 1 <= K <= number of tickets

Input Format for Custom Testing:

• The first line contains a string,Tickets, denoting the given cost of each ticket.
• The next line contains an integer, K, denoting the number of tickets that is to be removed.

Sample Cases:

• Sample Input 1
203
3
• Sample Output 1
0

### Question 5: HR Issues

Problem statement -:

Shovon is an HR in a renowned company and he is assigning people to work. Now he is assigning people work in a fashion where if he assigns somework a work of cost 2, the next person will be strictly getting a job with cost equal or more than 2. Given that Shovon’s company has infinite work and a number of employees, how many distributions can be possible. The cost of jobs can go 0 to 9.

Function Description:

Complete the special_numbers function in the editor below. It has the following parameter(s):

Parameters:

NameTypeDescription
NIntegerThe number of depts.
arr[ ]Integer arrayThe number of  employees in each dept..

Return: The function must return an INTEGER denoting the sum of answers for all distinct distributions.

Constraints:

• 1 <= n <= 100
• 1 <= arr[i] <= 200

Sample Cases:

• Sample Input 1
2
4
1
• Sample Output 1
725
• Description
The ans if m = 1 is 10, which is all numbers from 0 to 9
The ans for m = 2 is 55
The answer for m = 3 is 220
The answer for m = 4 is 715
So fun(4) + fun(1) = 725

### Question 6: Airport authority

Problem Statement -:

In an airport , the Airport  authority decides to charge some minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay \$1.

Function Description:

Complete the weight Machine function in the editor below. It has the following parameter(s):

Parameters:

NameTypeDescription
NIntegernumber of luggage
TIntegerweight of each luggage
weights[ ]Integer arraythreshold weight

Returns: The function must return an INTEGER denoting the required amount to be paid.

Constraints:

• 1 <= N <= 10^5
• 1 <= weights[i] <= 10^5
• 1 <= T <= 10^5

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of luggages.
• Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing weight of ith luggage.
• The next line contains an integer, T, denoting the threshold weight of the boundary wall.

Sample Cases:

• Sample Input 1
4
1
2
3
4
3
• Sample Output 1
5
• Explanation:
Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.

### Question 7: Find the homeless

Problem Statement -:  There are N Homeless people in the community and N houses in the community. It will be given in the array (people) , height of the person and in the array house capacity of the house is given.

Government decided to give homes for people on the basis of following conditions:

• Priority is given for the people from left to right of the array
• Each person is allotted to a house if and only if the capacity of house is greater than or equal to persons height
• Nearby empty Houses are alloted to the person( starting from extreme left)

You need to find the number of homeless people who have not allotted any home if the government follows the above conditions.So that government will have an idea for how many people they need to allot home for next time.

Constraints:

• 1 <= N <= 10^3
• 1 <= people[i] <= 10^5
• 1 <= house[i] <= 10^5

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of  people and number of houses.
• Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing peoplei.
• Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing housei.

Sample Test Cases

• Sample Input 1
3
4
2
7
3
5
10
• Sample Output 1
0
• Explanation
people=[4,2,7]
house=[3,5,10]
People[0] has more priority , from left to right order in houses 5 is the nearest one which fits for people[0]
people[1]=2 will fit in 3 which is nearer from left
people[2]=7 will fit in remaining house of capacity of 10
So no homeless people left so return 0
• Sample Input 2
3
3
8
5
1
9
4
• Sample Output 2
2
• Explanation
people=[3,8,5]
house=[1,9,4]
people[0]=3 can fit in 9 which is nearest from left in array house
people[1]=8  cannot fit in any home which is left (i.e, 1 and 4)
people[2]=5 cannot fit in any home which is left (i.e, 1 and 4)
So return 2,which is number of homeless people

### 7 comments on “InfyTQ Coding Questions 2023”

• Sakshi

Thank you for the questions. These helped me a lot in my preparations

• Ashish

What is the most important thing to learn to score good in InfyTQ?

• avik394451

I really like the solutions.Thank you.

• Shruti