Gold mine problem
You have been given a gold mine represented by a 2-d matrix of size ('N' * 'M') 'N' rows and 'M' columns. Each field/cell in this mine contains a positive integer, the amount of gold in kgs.
Initially, the miner is at the first column but can be at any row.
He can move only right, right up, or right down. That is from a given cell and the miner can move to the cell diagonally up towards the right or right or diagonally down towards the right.
Find out the maximum amount of gold he can collect.
Input Format:
The first line contains an integer 'T’, which denotes the number of Test cases.
The next '2' * 'T' lines represent the ‘T’ test cases.
The first line of each test case contains two single space-separated integers 'N' and 'M' denoting the size of the gold mine.
The second line of each test case contains 'N' * 'M' space-separated integers representing the gold mine.
Output Format:
For each test case print an integer 'X' denoting the maximum amount of gold collected.
Output for each test case will be printed in a separate line.
Note:
You are not required to print the output, it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= N <= 100
1 <= M <= 100
0 <= gold at each cell <= 10^5
Time Limit: 1 sec
CodingNinjas
author
2y
Recursive Solution
- The miner can start from any row of the first column, hence we will be calling our recursive function from all the rows of column 1 as the starting block/cell.
- In the recursive functi...read more
CodingNinjas
author
2y
Dynamic Programming Recursive Solution
- In the recursive solution, we can clearly see overlappings.
- A single cell might be visited many times, and we further need to calculate the best answer from that c...read more
CodingNinjas
author
2y
Iterative Approach
- Create a 2-D matrix ‘GOLD_TABLE’, the same size as the given mine, and initialize each cell of ‘GOLD_TABLE’ to ‘0’.
- Now start from the very last column of the mine and move towards th...read more
Add answer anonymously...
Top Samsung Frontend Developer Intern interview questions & answers
Popular interview questions of Frontend Developer Intern
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app