Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9bdd09e

Browse files
committed
Add a question
1 parent 84ba176 commit 9bdd09e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎README.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,3 +1478,41 @@ const rot13 = str => {
14781478
---
14791479

14801480
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1481+
1482+
## 45. Richest Customer Wealth
1483+
1484+
You are given an `m x n` integer grid `accounts`, where `accounts[i][j]` is the amount of money the `i`​​​​​​​​​​​th​​​​ customer has in the `j`​​​​​​​​​​​th​​​​ 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. For example:
1485+
1486+
```
1487+
Input: accounts = [[1,5],[7,3],[3,5]]
1488+
Output: 10
1489+
Explanation:
1490+
1st customer has wealth = 6
1491+
2nd customer has wealth = 10
1492+
3rd customer has wealth = 8
1493+
The 2nd customer is the richest with a wealth of 10.
1494+
```
1495+
1496+
```js
1497+
const maximumWealth = accounts => {
1498+
// Your solution
1499+
};
1500+
1501+
console.log(maximumWealth([[2,8,7],[7,1,3],[1,9,5]])); // 17
1502+
console.log(maximumWealth([[1,5],[7,3],[3,5]])); // 10
1503+
console.log(maximumWealth([[1,2,3],[3,2,1]])); // 6
1504+
```
1505+
1506+
<details><summary>Solution</summary>
1507+
1508+
```js
1509+
const maximumWealth = accounts => {
1510+
return Math.max(...accounts.map(customer => customer.reduce((a, b) => a + b)));
1511+
};
1512+
```
1513+
1514+
</details>
1515+
1516+
---
1517+
1518+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /