-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1672.js
20 lines (18 loc) · 885 Bytes
/
1672.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank.
// Return the wealth that the richest customer has.
// A customer's wealth is the amount of money they have in all their bank accounts.
// The richest customer is the customer that has the maximum wealth.
function maximumWealth(accounts) {
let theRichestCustomer = 0;
for (let i = 0; i < accounts.length; i++) {
let total = 0;
for (let j = 0; j < accounts[i].length; j++) {
total += accounts[i][j];
}
theRichestCustomer = Math.max(theRichestCustomer, total);
}
return console.log(theRichestCustomer);
}
maximumWealth([[1,2,3],[3,2,1]]); // 6
maximumWealth([[1,5],[7,3],[3,5]]); // 10
maximumWealth([[2,8,7],[7,1,3],[1,9,5]]); // 17