Robot Delivery Path Problem

You are tasked with directing a robot from the top-left corner of an N*N matrix to a specified point (x, y), delivering a parcel. The robot is restricted to move only on flat areas (denoted by 1), and can't move on obstacles (denoted by 0). The target position is marked with a 5. Determine if it is possible for the robot to reach the destination by moving downwards or rightwards without leaving the matrix boundaries.

Input:

Integer T, the number of test cases.
For each test case -
Integer N, defining the matrix size.
Integers x and y, the destination coordinates.
N lines each containing N space-separated integers (0, 1, or 5) representing the matrix.

Output:

For each test case, return true if the robot can reach the position (x, y). Otherwise, return false.

Example:

Input:
1
3 2 2
1 0 1
1 1 1
1 1 5
Output:
true
Explanation:

The robot starts at (0,0) and moves to (2,2) following the path (0,0) -> (1,0) -> (2,0) -> (2,1) -> (2,2).

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 100
  • matrix[i][j] values are 0, 1, or 5

Note that the robot starts at position (0,0) which is always marked as 1.

AnswerBot
1d

Determine if a robot can reach a specified destination in a matrix by moving only downwards or rightwards.

  • Start at (0,0) and move towards the destination (x, y) only downwards or rightwards.

  • Check if t...read more

Help your peers!
Add answer anonymously...
Amazon Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter