Issue # 32: IT training – current issues and challenges from leading companies

Hello dear readers. We again and again delight you with a new selection of interesting questions and tasks from interviews to leading IT companies!

By the way, the answers to the problems from the previous issue have already been published!

Issues will appear every week – stay tuned! The heading is supported by a recruiting agency. Spice IT.

This week we collected tasks from interviews at the Indian company MakeMyTrip.

Questions

1. 10 Coins Puzzle

You are blindfolded and 10 coins are place in front of you on table. You are allowed to touch the coins, but can’t tell which way up they are by feel. You are told that there are 5 coins head up, and 5 coins tails up but not which ones are which.

Can you make two piles of coins each with the same number of heads up? You can flip the coins any number of times.

Transfer

You are blindfolded and put 10 coins on the table in front of you. You can touch the coins, but to the touch you cannot determine which side the coins are up. You are told that there are 5 coins lying obverse (“tails”) up and 5 coins lying reverse (“tails”) up, but which ones are not said.

Can you make two piles of coins with the same number of coins lying obverse up? You can flip coins any number of times.

2. Newspaper puzzle

A newspaper made of 16 large sheets of paper folded in half. The newspaper has 64 pages altogether. The first sheet contains pages 1, 2, 63, 64.

If we pick up a sheet containing page number 45. What are the other pages that this sheet contains?

Transfer

The newspaper consists of 16 large sheets of paper folded in half. There are 64 pages in the newspaper. The first sheet contains pages 1, 2, 63, 64.

* newspaper folded in half

If we take a sheet containing page number 45. What other pages does this sheet contain?

Tasks

1. Transpose of matrix

Write a program to find transpose of a square matrix mat[][] of size N * N. Transpose of a matrix is ​​obtained by changing rows to columns and columns to rows.

Input:

The first line of input contains an integer T, denoting the number of testcases. Then T test cases follow. Each test case contains an integer N, denoting the size of the square matrix. Then in the next line are N * N space separated values ​​of the matrix.

Output:

For each test case output will be the space separated values ​​of the transpose of the matrix

Constraints:
1 <= T <= 15
1 <= N <= 20
-103 <= mat[i][j] <= 103

Example:
Input:

2
4
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
2
1 2 -9 -2

Output:
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
1 -9 2 -2

Explanation:
Testcase 1: The matrix after rotation will be: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4.

Transfer

Write a program to find the transposition of a square matrix mat[][] the size N * N. Matrix transposition is obtained by changing rows to columns and columns to rows.

Input:

The first line of input contains an integer Tdenoting the number of test sets. Then follow T test kits. Each test case contains an integer Ndenoting the size of the square matrix. Then in the next line are written with a space N * N matrix values.

Exit:

For each test, the output will be space-separated matrix transpose values

Limitations:
1 < = T <= 15
1 < = N <= 20
-103 < = mat[i] [j] < = 103

Example:
Input:

2
4
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
2
1 2 -9 -2

Exit:
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
1 -9 2 -2

Explanation:

Test 1: the matrix after transposition will be: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4.

2. Trailing zeroes in factorial

For an integer n find number of trailing zeroes in n!.

Input:

The first line contains an integer 'T'denoting the total number of test cases. In each test cases, it contains an integer 'N'.

Output:

In each seperate line output the answer to the problem.

Constraints:
1 <= T <= 100
1 <= N <= 1000

Example:
Input:

1
9

Output:
1

Transfer

For an integer n find the number of zeros at the end of a number n!.

Input:

The first line contains the integer 'T'denoting the total number of tests. Each test contains an integer 'N'.

Exit:

In each separate line print the answer to the problem.

Limitations:
1 < = T <= 100
1 < = N < = 1000

Example:
Input:

1
9

Exit:
1

3. Steps by knight

Given a square chessboard of N x N size, the position of Knight and position of a target is given. We need to find out minimum steps a Knight will take to reach the target position.

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the square chessboard. The next line contains the X-y coordinates of the knight. The next line contains the X-y coordinates of the target.

Output:

Print the minimum steps the Knight will take to reach the target position.

Constraints:
1<=T<=100
1<=N<=20
1<=knight_pos,targer_pos<=N

Example:
Input:

2
6
4 5
1 1
20
5 7
15 20

Output:
3
9

Transfer

On a square chessboard the size of N x N sets the position of the horse and the position of the target. We need to find out what minimal steps the horse will take to achieve the goal.

Input:

The first line of input contains an integer Tdenoting the number of tests. Then follow T tests. Each test contains an integer ndenoting the size of a square chessboard. The next line contains the coordinates X-y horse. The next line contains the coordinates X-y goals.

Exit:

Print the minimum steps that the horse will take to reach the target position.

Limitations:
1<=T<=100
1<=N<=20
1<=knight_pos,targer_pos<=N

Example:
Input:

2
6
4 5
1 1
20
5 7
15 20

Exit:
3
9

Answers to the tasks will be given during the next week - have time to solve it. Good luck

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *