InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Rat In a Maze

Problem Description

Given a grid A, a rat is at position (1, 1). He wants to go to the position (n, n) where n is size of the square matrix A.

1 represents a traversable cell and 0 represents a non-traversable cell. Rat can only move right or down.

Return a path that the rat can take.



Problem Constraints

1 <= |A| <= 4



Input Format

First and only argument is the vector of vectors A.



Output Format

Return a vector of vectors that denotes a path that can be taken.



Example Input

Input 1:

A = [   [1, 0]
        [1, 1]
    ]

Input 2:

A = [    [1, 1, 1]
         [1, 0, 1]
         [0, 0, 1]
    ]



Example Output

Output 1:

[   [1, 0]
    [1, 1]
]

Output 2:

[    [1, 1, 1]
     [0, 0, 1]
     [0, 0, 1]
]



Example Explanation

Explanation 1:

 Path is shown in output.

Explanation 2:

 Path is shown in output.



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Rat In a Maze on Interview Code Editor
Sign Up
to access hints and editorial solutions for Rat In a Maze

Discussion


Loading...
Click here to start solving coding interview questions