public class RichestCustomerWealth {
public static void main(String[] args) {
int[][] accounts = {
{1,2,3},
{4,5,6},
{7,8,9}
};
System.out.println(CustomerWealth(accounts));
}
public static int CustomerWealth(int[][] accounts) {
//person =ro
//account=col
int ans=Integer.MIN_VALUE;
for (int person = 0; person < accounts.length; person++) {
//when you start a new col ,take a new row
int sum=0;
for (int account = 0; account < accounts[person].length; account++) {
sum = sum + accounts[person][account];
}
//now we have sum of accounts of person
//check overall ans
if (sum > ans) {
ans = sum;
}
}
return ans;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter