Find minimum sum

Given an integer 2D matrix (of size n x n), find the smallest sum possible while moving from the element at (0,0) to the diagonally opposite end i.e. till the element at n x n.

Input matrix will be a square matrix of size n x n. While moving to the diagonally opposite end, the following rules are to be followed :
1. From a given element you can move to the element directly below it  
2. From a given element you can move to the element to right of it 

Keeping the following rules in mind, you have to return the smallest sum that is possible while moving to the diagonally opposite element.

Input format :

Line 1 : n

n lines containing matrix elements separated by space

Sample Input :
4 
1 10 10 10 
1 10 10 10 
1 10 10 10 
1  1  1  1 
Sample Output :
7

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem