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

The problem involves determining if a ninja can reach the destination in a maze by moving in four directions until hitting a wall.

  • Create a function that takes in the maze, starting point, and destinat...read more

Anonymous
6mo
Preafare
Help your peers!
Select
Add answer anonymously...

Bounteous x Accolite Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q2. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q3. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more
Bounteous x Accolite Software Developer Intern 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