InfyTQ Advantage Coding Round Question 2024

InfyTQ Advantage Round Coding
Question with Solutions PDF 2024

InfyTQ Advantage Round is an optional round for the candidates who will qualify the Certificate round(score >65%). This round is a coding test round, where you will have 3 coding questions with varied difficulty level. The better you perform in this round, the chances of a better package increases.

InfyTQ Advantage Coding Round Question 2024

Pattern for InfyTQ Advantage Round

  • There will be 3 coding questions in this round, with varied difficulty level.
  • Each question will have a different weight-age of marks, depending upon the difficulty level of that question.
  • You will be able to solve the questions only either in Java or Python, depending upon the language that you would have chosen at the time of booking the slots.
  • Clearing the Advantage round will give you a chance for a pre-replacement interview either for the post of Power Programmer or System Engineer Specialist based on their performance in the interview.
InfyTQ Advantage Round Coding Questions

Detailed analysis for InfyTQ Advantage Coding Round

TopicsNo. of Questions
Number of Questions3
Time Limit3 hrs(combined with MCQ)
Difficulty levelvery high
Package Offered5 LPA – 8 LPA

InfyTQ Advantage Round Practice Coding Questions

Question 1: TOR

Problem Statement-: Lets define Ternary numbers to be the positive integer numbers that consist of digits 0,1,2 only. Let’s also define the operation TOR(x,y) to be the following operation on two Trenary numbers x and y (its output is z = TOR(x,y)).

  1. Go through the digits one by one .
  2. For each digit i, the digit i in the output will be z[i] = (x[i] + y[i]) % 3

You are given a positive integer n, and a long positive integer c, your job is to find two Ternary   numbers a,b (of length n) where c = TOR(a,b) and max(a,b) is as minimum as possible. After finding that pair output max(a,b). If there’s no such pair, output -1.

 

  • Note 1: the given numbers won’t have any leading zeros.
  • Note 2: a,b should be of length n without leading zeros.
  • Note 3: since the answer can be very large, output it modulo 1000000007 (10^9 +7).

 

Function Description:

Complete the TOR function in the editor below. It has the following parameters(s):

Parameters:

NameTypeDescription
nintegerThe length of a and b
cstringThe number which should satisfy the equation c=TOR(a,b).

The function must return an INTEGER denoting the max(a,b) when it’s minimized.

 

Constraints: 

  • 1 <= n <=  10^5
  • 1 <=  len(c) <= 2*n

 

Input Format

  • The first line contains an integer, n, denoting the length of a and b .
  • The next line contains a string, c, denoting the number which should satisfy the equation c=TOR(a,b).

 

Sample Cases:

  • Sample input 1  
    2                                            
    22
  • Sample output
    11

Question 2 : Special LIS

Problem statement-:  Given an array of N integers. Find the length of the longest increasing subsequence such that the difference between adjacent elements of the longest increasing subsequence is also increasing.

Note: It’s not required that the sequence should have strictly increasing numbers and the differences are also not required to be strictly increasing.

Ex: [1,2,3,4,5]. The longest increasing subsequence will be [1,2,4,5] but the difference array in this case is [1,2,1] which is not increasing. If we consider [1,2,4] or [1,2,5] then the numbers as well as the differences are in increasing order.

Function Description:

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

Parameters:

NameTypeType
sizeIntegersize of array
arrInteger arrayarray

Return:

The function must return an INTEGER denoting the length of the longest increasing sub sequence with increasing differences.

Constraints:

  • 1 <= size <= 500
  • 1 <= arr[i] <= 10^5

Input Format:

  • The first line contains integer, size, denoting the size of the array.
  • Each line i of the size subsequent lines (where 0 <= i < size) contains an integer describing the ith elements of the array.

Sample Cases

  • Sample Input 1
    5
    1
    2
    3
    4
    5

 

  • Sample Output 1
    5

Question 3: Alisa In the Library

Problem Statement -:  Alisa is in the library, she wants to buy some different books, there are “nm” different chemistry books and k different science books. In how many different ways can Alisa select a book of mathematics, two books of chemistry, and some books of science?

Function Description:

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

Parameters:

NameTypeDescription
nIntegerthe number of mathematics books
mIntegerthe number of chemistry books
kIntegerthe number of science books
xIntegerthe number of books of science Alisa needs

Return: The function must return an INTEGER denoting the number of ways Alisa can buy the books she needs.

Constraints:

  • 1 <= n <= 10^6
  • 1 <= m <= 10^6
  • 1 <= k <= 10^6
  • 1 <= x <= 10^6

Input Format:

  • The first line contains an integer, n, denoting the number of mathematics books.
  • The next line contains an integer, m, denoting the number of chemistry books.
  • The next line contains an integer, k, denoting the number of science books.
  • The next line contains an integer, x, denoting the number of books of science Alisa needs.

OUTPUT DESCRIPTION

We have 5 different mathematics books, four different chemistry books, and two different science books which we have to choose all of them (d=2) so, we can choose 1 book out of five mathematics books in 5 ways, 2 out of 4 chemistry books in 6 ways, and we have only one way to choose 2 out of 2 science books, total: 5*6*1 = 30 ways. 

Sample Test Cases

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

Question 4: Palindromic Paths

Problem Statement-:  You are given a grid of size of N*M (1-based indexing). Each cell in the grid contains a lower case English alphabet (a-z). You have to replace some letters of the grid such that any path from (1,1) to (N,M) is a palindromic path. A path is palindromic if the string obtained by joining letters from the corresponding cells of a traversed path is a palindrome i.e. reads the same forward and backward. You are only allowed to move Right or Down in the grid.

Calculate the minimum number of letters that you need to replace such that any valid path from (1,1) to (N,M) is palindromic.

 

Function Description:

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

Parameters:

NameTypeDescription
nIntegerNumber of rows in the grid
mIntegernumber of columns in the grid
gridstring 2D arraythe given grid

Return: The function must return an integer denoting the minimum number of letters.

 

Constraints:

  • 1 <= N <= 10^3
  • 1 <= M <= 10^3
  • a <= grid[i][j] <= z

 

Input format for Custom Testing:

  • 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.
  • Each line i of the N subsequent lines (where 0 <= i <N) contains a string of lower-case English Alphabets of size M.

Sample Test Cases

  • Sample Input
    2
    2
    ac
    bc
  • Sample Output
    1
  • Explanation
    Change the letter at (2,2) to ‘a’, such that both paths become palindromes.
    Path1: (1,1) -> (1,2) -> (2,2)
    Path2: (1,1) -> (2,1) -> (2,2)

 

Question 5: Divisible by K

Problem Statement-: Alice has a non-negative integer x written in the base y (a numeral system where 2 <= y <= 16). The number x has distinct digits. Bob has a number k written in the decimal numeral system. Alice wanted to check if the number x is divisible by the number k. However, Bob thinks it’s a very easy task. That’s why he proposed another problem: count the number of permutations of x which result in a number divisible by k.

Alice is confused and doesn’t know how to solve Bob’s problem, can you help her?

Notes:

  1. y is given in decimal.
  2. The possible digits for x start with the usual digits (0-9), and then with the letters (A – F), depending on the value of y. For example, if y = 12 then the digits are [0,1,… 9, A, B]. Also when y = 3, the possible digits are [0,1,2].
  3.  Since x may contain letters, it’s inputted as a string.
  4.  It’s guaranteed that the number x is a valid number in the base y, and that it doesn’t contain leading zeroes.
  5. Since the final answer can be very large, output it modulo 1000000007 (10^9+7).

Function Description:

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

Parameters:

NameTypeDescription
yIntegerthe base which x is written in
kIntegerthe number which bob has
xStringAlice number written in the base y

Return: The function must return an INTEGER denoting the number of permutations of x which result in a number divisible by k.

Constraints:

  • 1 <= y <= 16
  • 1 <= k <= 20
  • 1 <= len(x) <= y

Input Format for custom testing:

  • The first line contains an integer, y, denoting the base which x is written in.
  • The next line contains an integer, k, denoting the number which Bob has.
  • The next line contains a string, x, denoting Alice’s number written in the base y.

Sample Cases:

  • Sample Input 1
    5
    4
    24
  • Sample Output 1
    0
  • Explanation
    24 in base 5, is 14 in decimal. 42 in base 5, is 22 in decimal. For in both cases the number is not divisible by 4. So the answer is 0

Question 6: 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 7 : 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 8: 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 9: 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 10: 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 11 : 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