-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxWealth.java
More file actions
26 lines (24 loc) · 791 Bytes
/
MaxWealth.java
File metadata and controls
26 lines (24 loc) · 791 Bytes
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
public class MaxWealth {
public static void main(String[] args) {
int[][] accounts={{1,2,3} , {3,2,1} };
System.out.println(maximumWealth(accounts));
}
static int maximumWealth(int[][] accounts) {
// person = rol
// account = col
int maxsum =0;
for (int i=0;i<accounts.length;i++) {
// when you start a new row, take a new sum for that row
int rowsum = 0;
for (int j=0;j<accounts[i].length;j++) {
rowsum += accounts[i][j];
}
// now we have sum of accounts of person
// check with overall ans
if (rowsum > maxsum) {
maxsum= rowsum;
}
}
return maxsum;
}
}