You are on page 1of 3

28/07/2017 TCS: CodeVita - Coding Arena

TCS NextStep    TCS Careers    www.tcs.com    Logout

Welcome RISHABH VASHISTHA Home Coding Arena Compile & Run Submissions Graphs Feedback

Time Left

Coding Arena  00 00 56
Change Default Language hr min sec

A B C D E F

Rules & Regulations
Problem : Ball Passing game
Launch Code Editor
 
TCS India has organized a blind folded ball passing game for two players.
  Notifications
They have a special kind of ground where playe B can throw the ball in any four directions (up, down, right, left).
 
Status messages

 
The ground consist of some slant poles on which.when the ball strikes the ball changes its direction by 90 degrees as shown
below.
 

 
If suppose you have thrown a ball in a direction in which there is no pole then the ball goes out of the stadium in that direction
 
The player B has the ball initially. The objective is to output the minimum steps in which B can pass the ball to A and also the
count of poles the ball has struck. If he can never pass the ball to A, then your output should be ­1.
 
If you get multiple minimum steps then output those steps in which the ball hits minimum no of barriers
 
For example, 
A 0 0 
0 0 

https://www.tcscodevita.com/CodevitaV6/problemstart.jsp 1/3
28/07/2017 TCS: CodeVita - Coding Arena
0 B 0
   
Here two outputs are possible 
   
4 3 and 4 1 but you have to print 4 1 as output as this path has minimum no of barriers .
 
Input Format:
 
First line containing the integer K indicating the size of the field
 
Next two lines each having a pair of integers separated by space giving the row and column numbers of the positions of A and
B respectively K lines of K integers each, separated by space, giving the positions of the barriers in the field ­ 0 indicating no
barrier, 1 indicating a / barrier and 2 indicating a barrier.

Output Format:
 
Minimum number of steps required for the ball to reach A 
 
Number of barriers ball on which the ball bounces

Constraints:
 
3 ≤ K ≤ 20

 
Example 1
 
Input 

0 3 
3 2 
0 0 1 0 
1 0 1 1 
0 0 0 0 
2 0 0 0
 

 
Output 
4 2
 
Explanation 
Shown in the figure above.

 
Example 2
 
Input 

2 2 
0 0 
0 0 1 
0 0 0 
0 0 0
 

https://www.tcscodevita.com/CodevitaV6/problemstart.jsp 2/3
28/07/2017 TCS: CodeVita - Coding Arena
 
Output 
­1
 
Explanation 
The ball goes out of the field after hitting the barrier at 1 3

Note:
 
Please do not use package and namespace in your code. For object oriented languages your code should be written in one
class.
Note:
 
Participants submitting solutions in C language should not use functions from <conio.h> / <process.h> as these files do not
exist in gcc
Note:
 
For C and C++, return type of main() function should be int.
 
 
© 2017 Tata Consultancy Services Limited. All Rights Reserved.
 

 
 
Submit Answer

 I , RISHABH VASHISTHA confirm that the answer submitted is my own. 
 I would like to provide attribution to the following sources. 
 
Select Language  

Select File  
  Browse...

© 2017 Tata Consultancy Services Limited. All Rights Reserved.    In Association with | Privacy Policy                

https://www.tcscodevita.com/CodevitaV6/problemstart.jsp 3/3

You might also like