Company-Specific Courses
Free Resources

Edit

Edit

InfyTQ Questions | InfyTQ Final Round Coding Qs (Python)

Published on 13 Apr 2021

This article covers the InfyTQ Final Round Coding Questions in Python. Post the initial Qualifying Round, the Final Round in InfyTQ is what determines whether candidates get the certificate of Infosys Certified Software Programmer and also potentially land a job offer in Infosys. What's covered in this article is solutions in Python to the InfyTQ Questions (Coding), which are part of the official sample paper.

InfyTQ Questions | InfyTQ Final Round Coding Questions (Python)

Question 1: Four in a line

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.

Example 1

Sample input:

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:

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.

Example 2

Sample input:

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:

-1

Explanation:

Here there are no sets of four consecutive elements of the same value either horizontally, vertically, or diagonally. Hence the output is-1

Code Solution in Python:

Input:

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

Python 3

Output
1

Question 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 until a palindrome is obtained

For example:

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

Input format: Read num from the standard input stream.

Output format: Print the palindrome calculated to the standard output stream.

Example 1

Sample input:

124

Sample output:

545

Explanation:

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

Example 2

Sample input:

4

Sample output:

8

Explanation:

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

Code Solution in Python:

Input: 124

Python 3

Output
545

If you want to check out video explanation of these questions, please watch the video below.

Suggested Articles:

InfyTQ Questions and Answers | Java Qualifying Round

InfyTQ Questions and Answers | Python Qualifying Round

InfyTQ 2022 batch | Infosys InfyTQ Registration & Process

HackWithInfy 2021 | Infosys Coding Contest for 2022 batch

InfyTQ Questions and Answers | Aptitude Qualifying Round

InfyTQ Questions | InfyTQ Final Round DBMS Questions

InfyTQ Questions | Python MCQs | Final Round

InfyTQ Questions | InfyTQ Final Round Java MCQs