Gold Mine Problem Statement

You are provided with a gold mine, represented as a 2-dimensional matrix of size N x M with N rows and M columns. Each cell in this matrix contains a positive integer representing the amount of gold (in kgs) at that location.

Initially, the miner is positioned at the first column in any row. From any given cell, the miner can travel in either of the following directions: right, right-up, or right-down.

Your task is to determine the maximum amount of gold that the miner can collect by only moving in the allowed directions.

Input:

The first line contains an integer 'T', denoting the number of test cases.
Each test case consists of two lines:
1. The first line contains two space-separated integers, 'N' and 'M', which represent the dimensions of the gold mine.
2. The second line contains N * M space-separated integers that form the gold mine matrix.

Output:

For each test case, output an integer 'X' indicating the maximum amount of gold that can be collected.
Print the output for each test case on a new line.

Example:

T = 1
N = 3, M = 3
Gold Mine Matrix:
1 3 1
2 1 4
0 6 4
The output will be:
12

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 100
  • 1 ≤ M ≤ 100
  • 0 ≤ gold in each cell ≤ 105

Time Limit: 1 second

Note:

No need to print the output; just implement the function logic to achieve the solution.
AnswerBot
4mo

The task is to determine the maximum amount of gold a miner can collect by moving in allowed directions in a 2D gold mine matrix.

  • Create a function that takes the gold mine matrix and dimensions as inp...read more

Help your peers!
Select
Add answer anonymously...

Samsung Frontend Developer Intern interview questions & answers

A Frontend Developer Intern was asked Q. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Frontend Developer Intern was asked Q. What is a process in an operating system?
A Frontend Developer Intern was asked Q. Cousins of a Given Node in a Binary Tree Given a binary tree with 'N' nodes and ...read more

Popular interview questions of Frontend Developer Intern

A Frontend Developer Intern was asked Q1. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Frontend Developer Intern was asked Q2. What is a process in an operating system?
A Frontend Developer Intern was asked Q3. Cousins of a Given Node in a Binary Tree Given a binary tree with 'N' nodes and ...read more
Samsung Frontend Developer Intern 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