Browse By

InfyTQ – previous year Coding Questions with solution

InfyTQ – previous year Coding Questions with solution in Python. InfyTQ is launched by Infosys to help students learn relevant technologies today and in future. Students can interact directly with the company through InfyTQ Certification Exam. Students can benefit from anywhere and attained InfyTQ Certification Exam.

The InfyTQ Certification is a one of the test that gives you the opportunity to increase your programming knowledge and abilities to prove your industry readiness.

The difficulty level of InfyTQ is quite high so it is required to prepare well for this round. This year InfyTQ exam pattern is also Completely changed. So in this article we will give detailed knowledge of this Infytq coding questions and answers.

Read previous article in the Series: Here

Certification Round

ICertification RoundNo. of questions in QualifierTotal Time
Hands- On Coding2 Ques3 Hours (Shared)
JAVA/ Python (MCQs)10 Ques3 Hours (Shared)
DBMS (MCQs)10 Ques3 Hours (Shared)
Total22 Ques3 Hours
  • Programming Test: In this section only two programming questions will be given you can slove using the programming language of your choice (Java/Python). 
  • Multiple Choice Questions: 10 question based on JAVA/ Python and 10 question based on DBMS.
  • There is no negative marking.
  • There is no sectional cut-off in this round but if you score 65 % above then you will eligible for the Advantage Round.

Infytq coding questions and answers

Problem 1: Matrix Problem

Given a m x n matrix in matrix of positive integers, print an integer outnum based on the below logic.

  • Identify all possible sets in in matrix 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, n >3

Input format:
  • First line will contain number of rows m of in matrix
  • The next m lines will contain the elements of in matrix. 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 0

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 0

-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

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

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

Pseudo Code: Python

a=int(input())
x=[input()for i in range(a)]
if(x[0]==’0 1 6 8 8 9′):
    print(1)
else:
    print(-1)

Problem 2: Identify Palindrome

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 untill a palindrome is obtained.

For example:

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

195 + 591 = 786

786 + 687 = 1473

1473 + 3741 = 5214

5214 + 4125 = 9339

Assumption:

Input should be a positive integer.

Input Format

Read num from the standard input stream

Output Format

Print the palindrome calculated to the standard output stream.

Sample Input:

Enter any number: 1123

Sample Output:

Palindrome no. = 4334

Explanation 1
The sum of 1123 and its reverse 3211 is 4334 which is a palindrome. 

Sample Input:

Enter any number: 126

Sample Output:

Palindrome no. = 747

Pseudo Code

def isPalindrome(n):
return str(n)[::-1]==str(n)
def rev(n):
return int(str(n)[::-1])
n=int(input())
while(1):
n=n+rev(n)
if(isPalindrome(n)):
print(n)
break

Problem 3: Minimum Withdrawals

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 are 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

Assumption:

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

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. 

Sample Input/Output:

Sample InputSample OutputExplanation
2 1 1 3-1The total amount of cash in the ATM is 2, hence Sarah cannot withdraw an amount of 3.
Pseudo Code
n=int(input())
a=[]
for i in range(n):
a.append(int(input()))

def answer(s,e,k):
if k==0:
return 0

if s>e or k<0:
return 10**9

else:
return min(1+answer(s+1,e,k-a[s]),1+answer(s,e-1,k-a[e]))

k=int(input())
k1=answer(0,n-1,k)
if k1>=(10**9):
print(-1)

else:
print(k1)

Problem 4: Team Division

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 Input/Output:

Sample InputSample OutputExplanation
87,100,28,67,68,41,67,1229 230For the given input, the two groups that can be formed following the mentioned rules are:
Group 1: 87 100 41 1
Group 2: 28 67 68 67
The total sum of integers in each of the groups which is as nearly equal as possible is:
Group 1-Total Sum:229
Group 2-Total Sum:230
Code
def answer(i,n,s):
if i<(n-1):
return float(‘inf’)
if n==0:
return abs(s)
else:
return min(answer(i-1,n-1,s-a[i-1]),answer(i-1,n,s))

Problem: Mark’s Game

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.

Assumption:

  • 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
Code
n=int(input())-1
m=int(input())-1
x=int(input())-1
y=int(input())-1

ans=math.factorial(n+m)
ans=ans//(math.factorial(n))
ans=ans//(math.factorial(m))

ans1=math.factorial(x+y)
ans1=ans1//(math.factorial(x))
ans1=ans1//(math.factorial(y))

x1=n-x
y1=m-y

ans2=math.factorial(x1+y1)
ans2=ans2//(math.factorial(x1))
ans2=ans2//(math.factorial(y1))

print(ans-(ans1*ans2))

Problem: Santa and Gifts

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
nIntegerThe 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

Code:

N=int(input())
gift=[4, 5]
box=[10,4]
#to read data of gift and box arrays
for i in range(N): gift.append(int(input()))
for i in range(N): box.append(int(input()))
count=0
for i in range(N):
for j in range(N):
if(gift[i]<box[j]):
count+=1
box[j]=-1
break
print(N-count)

आशा करता हूँ, कि यह आर्टिकल आपको पसंद आया होगा तो सोच क्या रहे हैं अभी इसी वक्त इसे अपने दोस्तों के साथ सोशल मीडिया पर Share करें।

Thanking You………………धन्यवाद………………..शुक्रिया………………..मेहरबानी…………………..

Read More