Paths in a Matrix Problem Statement

Given an 'M x N' matrix, print all the possible paths from the top-left corner to the bottom-right corner. You can only move either right (from (i,j) to (i,j+1)) or down (from (i,j) to (i+1,j)).

Example:

Input:
M = 2, N = 3
matrix = [[1, 2, 3], [4, 5, 6]]
Output:
(1 2 3 6)
(1 2 5 6)
(1 4 5 6)
Explanation:

For the given 2x3 matrix, possible paths are (1 2 3 6), (1 2 5 6), and (1 4 5 6).

Constraints:

  • 1 <= M, N <= 10
  • Time Limit: 1 sec
Note:

You can return the paths in any order. You do not need to print anything; it's already handled. Implement the function to accomplish this task.

AnswerBot
4mo

Print all possible paths from top-left to bottom-right in a matrix by moving only right or down.

  • Use backtracking to explore all possible paths from top-left to bottom-right in the matrix.

  • At each cell,...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Virtusa Consulting Services

Q. What Java testing have you done?
Q. What is encapsulation?
Q. What is a copy constructor?
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