`{"id":"e995deb2-c655-4a69-bbc9-7580110ff89c","name":"Gold Mine - 2","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers, representing elements of 2d array a, which represents a gold mine.\r\n4. You are allowed to take one step left, right, up or down from your current position.\r\n5. You can't visit a cell with 0 gold and the same cell more than once. \r\n6. Each cell has a value that is the amount of gold available in the cell.\r\n7. You are required to identify the maximum amount of gold that can be dug out from the mine if \r\n you start and stop collecting gold from any position in the grid that has some gold.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne12\r\ne22..\r\nm*n numbers","outputFormat":"Maximum gold collected","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= m &lt;= 10\r\n0 &lt;= e1, e2, .. n * m elements &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\tstatic int max = 0;\r\n\tpublic static void getMaxGold(int[][] arr){\r\n\t\t//write your code here\r\n\t\t\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint m = scn.nextInt();\r\n\t\tint[][] arr = new int[m][n];\r\n\t\tfor(int i = 0; i < arr.length; i++){\r\n\t\t\tfor(int j = 0 ; j < arr[0].length; j++){\r\n\t\t\t\tarr[i][j] = scn.nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\t\tgetMaxGold(arr);\r\n\t\tSystem.out.println(max);\r\n\t}\r\n\t\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n6\r\n0 1 4 2 8 2\r\n4 3 6 5 0 4\r\n1 2 4 1 4 6\r\n2 0 7 3 2 2\r\n3 1 5 9 2 4\r\n2 7 0 8 5 1","sampleOutput":"120\r\n","questionVideo":"https://www.youtube.com/embed/lNwXq3Ki32I?start=0&end=125","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"e4a207f4-1277-4cbf-9dbf-b1bd0a8a47e1","name":"Gold Mine - 2","slug":"gold-mine-2","type":1}],"next":{"id":"46f278e4-1a53-4b86-b2e7-e3fb6b31c02a","name":"Gold Mine MCQ","type":0,"slug":"gold-mine-mcq"},"prev":{"id":"3a510807-2123-463a-acfd-339959f901e3","name":"Lexicographical numbers MCQ","type":0,"slug":"lexicographical-numbers-mcq"}}}`

# Gold Mine - 2

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers, representing elements of 2d array a, which represents a gold mine. 4. You are allowed to take one step left, right, up or down from your current position. 5. You can't visit a cell with 0 gold and the same cell more than once. 6. Each cell has a value that is the amount of gold available in the cell. 7. You are required to identify the maximum amount of gold that can be dug out from the mine if you start and stop collecting gold from any position in the grid that has some gold. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

`{"id":"e995deb2-c655-4a69-bbc9-7580110ff89c","name":"Gold Mine - 2","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers, representing elements of 2d array a, which represents a gold mine.\r\n4. You are allowed to take one step left, right, up or down from your current position.\r\n5. You can't visit a cell with 0 gold and the same cell more than once. \r\n6. Each cell has a value that is the amount of gold available in the cell.\r\n7. You are required to identify the maximum amount of gold that can be dug out from the mine if \r\n you start and stop collecting gold from any position in the grid that has some gold.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne12\r\ne22..\r\nm*n numbers","outputFormat":"Maximum gold collected","constraints":"1 &lt;= n &lt;= 10\r\n1 &lt;= m &lt;= 10\r\n0 &lt;= e1, e2, .. n * m elements &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\tstatic int max = 0;\r\n\tpublic static void getMaxGold(int[][] arr){\r\n\t\t//write your code here\r\n\t\t\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint m = scn.nextInt();\r\n\t\tint[][] arr = new int[m][n];\r\n\t\tfor(int i = 0; i < arr.length; i++){\r\n\t\t\tfor(int j = 0 ; j < arr[0].length; j++){\r\n\t\t\t\tarr[i][j] = scn.nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\t\tgetMaxGold(arr);\r\n\t\tSystem.out.println(max);\r\n\t}\r\n\t\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n6\r\n0 1 4 2 8 2\r\n4 3 6 5 0 4\r\n1 2 4 1 4 6\r\n2 0 7 3 2 2\r\n3 1 5 9 2 4\r\n2 7 0 8 5 1","sampleOutput":"120\r\n","questionVideo":"https://www.youtube.com/embed/lNwXq3Ki32I?start=0&end=125","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"e4a207f4-1277-4cbf-9dbf-b1bd0a8a47e1","name":"Gold Mine - 2","slug":"gold-mine-2","type":1}],"next":{"id":"46f278e4-1a53-4b86-b2e7-e3fb6b31c02a","name":"Gold Mine MCQ","type":0,"slug":"gold-mine-mcq"},"prev":{"id":"3a510807-2123-463a-acfd-339959f901e3","name":"Lexicographical numbers MCQ","type":0,"slug":"lexicographical-numbers-mcq"}}}`

Editor

# Gold Mine - 2

easy

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers, representing elements of 2d array a, which represents a gold mine. 4. You are allowed to take one step left, right, up or down from your current position. 5. You can't visit a cell with 0 gold and the same cell more than once. 6. Each cell has a value that is the amount of gold available in the cell. 7. You are required to identify the maximum amount of gold that can be dug out from the mine if you start and stop collecting gold from any position in the grid that has some gold. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

## Constraints

1 <= n <= 10 1 <= m <= 10 0 <= e1, e2, .. n * m elements <= 1000

## Format

### Input

A number n A number m e11 e12.. e12 e22.. m*n numbers

### Output

Maximum gold collected

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 6 0 1 4 2 8 2 4 3 6 5 0 4 1 2 4 1 4 6 2 0 7 3 2 2 3 1 5 9 2 4 2 7 0 8 5 1```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}120 ```

Question Video

Discussions

Show Discussion

Related Resources