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.

Be the first one to answer
Add answer anonymously...
JPMorgan Chase & Co. Machine Learning Engineer 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