← Back to DSA Animator
Richest Customer Wealth LC #1672 Easy Array · Matrix
Problem

You are given an m×n integer grid accounts where accounts[i][j] is the amount the i-th customer has in the j-th bank. Return the wealth of the richest customer (max row sum).

Example 1
Input: accounts = [[1,2,3],[3,2,1]]
Output: 6
Explanation: Both customers have wealth 6.
Constraints: 1≤m,n≤50  |  1≤accounts[i][j]≤100
Try Examples
Custom:
Approach
Row Sum + Track Maximum
For each customer (row), sum all their bank accounts. Track the running maximum. The answer is the largest row sum seen across all customers.
Accounts Matrix
Variables
Customer i
Account j
Row Sum
maxWealth
0
Step Logic
Press ▶ Play or Next Step to begin.
🎉
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Init maxWealth = 0
2
For each customer row: compute rowSum
3
Update maxWealth = max(maxWealth, rowSum)
4
Return maxWealth
Time
O(m·n)
Space
O(1)
Why It Works

A customer's wealth = sum of all their bank accounts (one matrix row). We simply compute each row sum and track the maximum — no sorting or extra space needed. One nested loop covers all m×n cells.