38. Richest Account
A bank keeps a table of balances: each row belongs to one customer, and the numbers in that row are the balances of that customer's accounts at the different branches. A customer's wealth is the total of all the balances in their row.
Write a method maxWealth that takes the two-dimensional array accounts, where accounts[i][j] is the balance customer i holds at branch j, and returns the wealth of the richest customer, meaning the largest row total.
Example 1
- Input:
- accounts = [[1,5],[7,3],[3,5]]
- Output:
- 10
- Explanation:
The row totals are 6, 10 and 8. The richest customer is the second one, with 10.
Example 2
- Input:
- accounts = [[2,8,7],[7,1,3],[1,9,5]]
- Output:
- 17
- Explanation:
The totals are 17, 11 and 15, so the answer is 17.
Constraints
1 ≤ accounts.length ≤ 50
1 ≤ accounts[i].length ≤ 50
0 ≤ accounts[i][j] ≤ 105
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(m * n)
- Space
- O(1)