Ninja and the Maze Problem Statement

Ninja is stuck in a maze represented as a 2D grid. He can move in four directions (Up, Down, Left, Right) until he hits a wall ('1'). Once stopped, he can choose a new direction. Determine if Ninja can reach the destination from the starting point.

Example:

Input:
maze = [[0, 0, 1], [1, 0, 0], [1, 0, 0]]
start = [2, 2]
destination = [0, 0]
Output:
True
Explanation:

Ninja can reach the destination using paths such as [left -> up -> left] or [up -> left -> up -> left].

Input:

The first line contains an integer ‘T’ denoting number of test cases.
Each test case includes:
- Two integers ‘M’ and ‘N’ marking maze dimensions.
- An ‘M’x‘N’ matrix representing the maze.
- Two integers for starting point coordinates.
- Two integers for destination coordinates.

Output:

For each test case, print 'True' if path exists, otherwise 'False'.

Constraints:

  • 1 <= T <= 50
  • 1 <= M, N <= 100
  • 0 <= MAZE[i][j] <= 1
Note:

No need to print; focus on implementing the function.

AnswerBot
4mo

Determine if Ninja can reach the destination in a maze by moving in four directions until hitting a wall.

  • Create a function to traverse the maze using depth-first search or breadth-first search.

  • Keep tr...read more

Help your peers!
Select
Add answer anonymously...

JUSPAY Software Developer interview questions & answers

A Software Developer was asked 1mo agoQ. What is a multithreaded environment, and how would you develop an application th...read more
A Software Developer was asked Q. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer was asked Q. Largest Cycle in Maze Problem Statement Given a maze represented by 'N' cells nu...read more

Popular interview questions of Software Developer

A Software Developer was asked 1mo agoQ1. What is a multithreaded environment, and how would you develop an application th...read more
A Software Developer was asked Q2. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer was asked Q3. Largest Cycle in Maze Problem Statement Given a maze represented by 'N' cells nu...read more
JUSPAY Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits