InfyTQ Final round Coding Questions

InfyTQ Final Round Coding Questions 2022

InfyTQ Final Round Coding Questions and Solutions 2023

Infosys Competition test has two rounds.

  • Qualifier Round
  • Final Round

The first round is the qualifier round which consists of mcq questions and the second round is the final round which consists of domain specific mcq questions and coding questions. Clearing this round will get you placed in Infosys at a package of 3.5LPA to 4LPA. The difficulty level of Final Round of Infytq is higher than the qualifier round.

Pattern analysis for InfyTQ Final Round

TopicsNo. of Questions
Number of Questions2 Coding + 20 MCQs
Time Limit2 hrs(combined with MCQ)
Difficulty levelvery high
Package Offered5 LPA – 7.5 LPA

InfyTQ Final Round Practice Coding Questions for Freshers

Question 1: Four in a line

Problem Statement -: Given a m x n matrix inmatrix of positive integers, print an integer outnum based on the below logic: 

  • Identify all possible sets in inmatrix that contain at least four consecutive elements of the same value val, either horizontally, vertically, or diagonally 
  • If only one set of consecutive elements is identified, store the value val in outnum 
  • If more than one set of consecutive elements is identified, find the smallest value and store it in outnum 
  • If no set of four consecutive elements of the same value is identified either horizontally, vertically, or diagonally, print -1 

Assumption: 

  • m and n will be greater than 3 

Input format: 

  • First line will contain number of rows m of inmatrix
  • The next m lines will contain the elements of inmatrix. Each line will have n elements separated by space.
  • Read the input from the standard input stream. 

Output format: 

  • Print outnum to the standard output stream. 

 

  • Sample Input 1
    5
    0 1 6 8 8 9
    5 6 1 6 8 9 
    6 5 6 1 1 9
    1 6 6 1 1 9
    6 3 3 3 3 9
  • Sample Output 1
    1
  • Explanation 1
    Following elements are present consecutively at least four times: Element 3 horizontally in the 5th row. Element 1 diagonally starting from the 2nd column in the first row. Element 6 diagonally starting from the 4th column in the second row. Element 9 vertically in the 6th column. As element 1 is the smallest value of the four identified sets of consecutive values, the output is 1  



  • Sample input 2
    5
    0 1 6 8 6 0
    5 5 2 1 8 2
    6 5 6 1 1 9
    1 5 6 1 4 0
    3 7 3 3 4 0 
  • Sample Output 2
    -1
  • Explanation 2
    Here there are no sets of four consecutive elements of the same value either horizontally, vertically,or diagonally  hence output is -1

Question 2 : Identify Palindrome

Problem Statement-: For a given positive number num, identify the palindrome formed by performing the following operations-

  • Add num and its reverse 
  • Check whether the sum is palindrome or not. If not, add the sum and its reverse and repeat the process until a palindrome is obtained 

For example: 

If original integer is 195, we get 9,339 as the resulting palindrome after the fourth addition: 

   195

+ 591

————–

   786

+ 687

————–

   1473

+ 3741

————–

   5214

+ 4125

———-

  9339

Input format: 

  • Read num from the standard input stream. 

Output format: 

  • Print the palindrome calculated to the standard output stream. 

Sample Test Cases

  • Sample Input 1
    124 

  • Sample Output 1
    545 

  • Explanation 1
    The sum of 124 and its reverse 421 is 545 which is a palindrome. 

 

 

  • Sample input 1
    4

  • Sample output 1
    8

  • Explanation 1
    The sum of 4 and its reverse 4 is 8 which is a palindrome.

Question 3: Minimum Withdrawals

Problem Statement-: There is a unique ATM in Wonderland. Imagine this ATM as an array of numbers. You can withdraw cash only from either ends of the array. Sarah wants to withdraw X amount of cash from the ATM. What is the minimum number of withdrawals Sarah would need to accumulate X amount of cash. If it is not possible for Sarah to withdraw X amount, return -1. 

Input Format 

  • The first line contains an integer, N, denoting the number of elements in ATM. 
  • Each line i of the N subsequent lines (where 0 <= i < N) contains an integer describing the cash in the ATM. 
  • The next line contains an integer, X, denoting the total amount to withdraw. 

Constraints 

  • 1 <= N <= 10^5 
  • 1 <= ATM [i] <= 10^5 
  • 1 <= X <= 10^5 

Sample Test Cases

  • Sample Input
    2
    1
    1
  • Sample Output
    -1 
  • Explanation
    The total amount of cash in the ATM is 2, hence Sarah cannot withdraw an amount of 3.

Question 4: Team Division

Problem Statement -: Consider an array inarr containing at least two non-zero positive integers ranging between 1 to 300 (inclusive of the boundary values). Divide the integers in inarr into two groups based on the below rules:

  1. Each of the integers should belong to either of the two groups
  2. The total sum of integers in each of the groups must be as nearly equal as possible
  3. The total number of integers between the two groups should not differ by more than 1

Print, outnum1 and outnum2, the sum of the integers of two groups separated by a space. If outnum1 and outnum2 are not equal, then print the smaller sum followed by the larger sum.

Input Format:

  • Read the array inarr elements separated by (‘,’) comma.
  • Read the input from the standard input stream.

Output Format:

  • Print outnum1 and outnum2 in the required order separated by a space.
  • Print the output to the standard output stream.

 

Sample Test Cases

  • Sample Input
    87,100,28,67,68,41,67,1

  • Sample Output
    229 230

 

Explanation

For the given input, the two groups that can be formed following the mentioned rules are:

  1. Group 1: 87 100 41 1
  2. Group 2: 28 67 68 67

The total sum of integers in each of the groups which is as nearly equal as possible is:

  1. Group 1-Total Sum:229
  2. Group 2-Total Sum:230

The total number of integers between group 1 and 2 differ by O integer.

Question 5: Mark’s Game

Problem Statement-:  Mark is playing a game on a 2D map. The 2D map is a rectangle of size n*m, where n is the number of rows, and m is the number of columns. The cell (1,1) is located at the top left corner of the map, and the cell (n,m) is located at the bottom right corner.

In one step, Mark can move from any cell to any of the adjacent cells (UP, DOWN, RIGHT, or LEFT). There’s also a blocked cell (x,y) which Mark can’t pass on. Mark can’t go off the map.

The goal of the game is to reach the cell (n,m). Mark is initially at cell (1,1) and he wants to achieve the goal of the game in the minimum number of steps. Now he’s wondering how many paths he can take such that the number of steps is minimized and he gets to cell (n,m). Can you help him find this number?

It is guaranteed that both cells (1,1) and (n,m) are NOT blocked.

 

Function Description:

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


Parameters: 

NameTypeDescription
nIntegerThe number of rows in the map.
mIntegerThe number of columns in the map.
xIntegerThe blocked cell’s row.
yIntegerThe blocked 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 map.
  • The next line contains an integer m, denoting the number of columns in the map.
  • The next line contains an integer, x, denoting the blocked cell’s row.
  • The next line contains an integer, y, denoting the blocked cell’s column.

Sample Test Cases

  • Sample Input 1
    2
    2
    2
    1
  • Sample Output 1
    1

Question 6 : Santa and Gifts

Problem statement-:   Christmas is here! Santa has already prepared the gifts for all children all around the world, however, he hasn’t picked them yet. Santa has N gifts, their sizes are given in an array, A, and he also has N boxes, their sizes are given in an array, B.

Santa packs the gifts in the boxes in the following way:

  1. He tries to put the gifts inside boxes from left to right.
  2. He goes through the boxes from left to right until he finds the first empty box that fits the current gift (the box’s size should be larger or equal to the current gift’s size), and Santa puts the current gift in that box.
  3. Santa moves to the next gift to the right.

You need to find the number of gifts which won’t be packed following Santa’s algorithms in packing the gifts.

Function Description:

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

Parameters:

NameTypeDescription
nInteger

The number of gifts and boxes

aInteger arrayThe size of gifts
bInteger arrayThe size of the boxes

Return:

The function must return an INTEGER denoting the number of gifts which won’t be packed.

Constraints:

  • 1 <= N <= 10^3
  • 1 <= A[i] <= 10^5
  • 1 <= B[i] <= 10^5

Input Format for Custom Testing:

  • The first line contains an integer, N, denoting the number of elements in A.
  • Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing Ai.
  • Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing Bi.

Sample Test Cases

  • Sample Input 1
    2
    4
    5
    10
    4
  • Sample Output 1
    1