Minimum Cost Path Problem Statement

Given an N x M matrix filled with integers, determine the minimum sum obtainable from a path that starts at a specified cell (x, y) and ends at the top left corner of the matrix (1, 1).

Explanation:

You can move in the following directions from any cell:

  • Down: to cell (row+1, col)
  • Right: to cell (row, col+1)
  • Down right diagonal: to cell (row+1, col+1)

Input:

The first line will contain two integers ‘N’ and ‘M’ denoting the number of rows and columns, respectively. Next ‘N’ lines contain ‘M’ space-separated integers each denoting the elements in the matrix. The last line will contain two integers ‘x’ and ‘y’ denoting the cell to start from. 

Output:

For each test case, print an integer that represents the minimum sum that can be obtained by traveling a path as described above. Output for every test case will be printed in a separate line. 

Example:

Input:
3 3
4 8 2
2 5 7
6 1 9
3 3
Output:
14
Explanation:

Starting from cell (3, 3), one minimum path is 9 → 1 → 2 → 2, thus the minimum sum is 14.

Constraints:

  • 1 <= T <= 50
  • 1 <= N, M <= 100
  • -10000 <= cost[i][j] <= 10000
  • 1 <= x, y <= 100
  • Time limit: 1 sec
Note:
You don’t need to print anything; It has already been taken care of.
AnswerBot
4mo

The problem involves finding the minimum sum path from a specified cell to the top left corner of a matrix.

  • Start from the specified cell and calculate the minimum sum path to reach the top left corner...read more

Help your peers!
Select
Add answer anonymously...

Cisco Consultant Engineer interview questions & answers

A Consultant Engineer was asked Q. Minimum Cost Path Problem Statement Given an N x M matrix filled with integers, ...read more
A Consultant Engineer was asked Q. Covid Vaccination Distribution Problem As the Government ramps up vaccination dr...read more
A Consultant Engineer was asked Q. Can you describe how a website sends data to a server?

Popular interview questions of Consultant Engineer

A Consultant Engineer was asked Q1. Minimum Cost Path Problem Statement Given an N x M matrix filled with integers, ...read more
A Consultant Engineer was asked Q2. Covid Vaccination Distribution Problem As the Government ramps up vaccination dr...read more
A Consultant Engineer was asked Q3. Can you describe how a website sends data to a server?
Cisco Consultant Engineer 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