-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichestCusWealth.java
40 lines (28 loc) · 1.11 KB
/
RichestCusWealth.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Arrays;
import static java.lang.Math.max;
public class RichestCusWealth {
public static void main(String[] args) {
int [][] Account = {{1,2,3},
{3,2,4}};
int ans = MaxWealth(Account);
System.out.println(ans);
}
static int MaxWealth (int [][] arr){
int maxwealth =0;
for (int i = 0; i < arr.length ; i++) {
int sum = 0;
for (int j = 0; j <arr[i].length; j++) { //inner for loop start from index 1 to sum
sum = sum + arr[i][j]; // sum of 2D arrays and 1D arrays together? //Iterative summation is required for update an new array
}
maxwealth = Math.max(maxwealth,sum);
// return 2D array in inner loop required?
}
//Scoping, we can only return value which is in same level
return maxwealth;
/*
* Time complexity = rows*cols
* space complexity = constant since no new varibles are creating +no recursion
*
* */
}
}