639/670

639. Richest Customer Wealth

Easy

A bank tracks its customers in an m × n grid accounts, where accounts[i][j] is the amount of money customer i keeps in bank j. A customer's wealth is the total across all of their accounts — the sum of row i.

Return the wealth of the richest customer, i.e. the largest row sum in the grid.

Row sums of the accounts gridEach customer's wealth is a row sum. In example 1 the sums are 17, 11, and 15 — the answer is 17.
accounts (banks →, customers ↓)287713195sum = 17sum = 11sum = 15richest customer holds 17

Example 1:

Input: accounts = [[2, 8, 7], [7, 1, 3], [1, 9, 5]]

Output: 17

Explanation: Row sums are 2+8+7 = 17, 7+1+3 = 11, and 1+9+5 = 15. Customer 0 is the richest with 17.

Example 2:

Input: accounts = [[1, 5], [7, 3], [3, 5]]

Output: 10

Explanation: The three customers hold 6, 10, and 8 in total; the largest is 10.

Example 3:

Input: accounts = [[1, 2, 3], [3, 2, 1]]

Output: 6

Explanation: Both customers total 6 — ties are fine because only the amount is asked for, not who holds it.

Constraints:

  • 1 ≤ m, n ≤ 50
  • 1 ≤ accounts[i][j] ≤ 100

Hints:

One customer = one row. The wealth of customer i is simply the sum of row i.

You never need to store all the sums — keep a single running maximum and update it as you finish each row.

▶ Run checks these sample cases. Submit also runs hidden edge cases.

Input: accounts = [[2, 8, 7], [7, 1, 3], [1, 9, 5]]

Expected output: 17