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).
accounts = [[1,2,3],[3,2,1]]6maxWealth = 0rowSummaxWealth = max(maxWealth, rowSum)maxWealthA 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.
There's no trick to avoid here: every account must be counted once. The only thing to get right is summing each row, then keeping the maximum.
Go row by row. Sum the row, and compare it with the best wealth seen so far.
Row sums plus a running maximum. In a 2D grid, the outer loop picks the row, and the inner loop walks its columns.
Run the animation above on your own input, or watch the 1:11 video explanation of Richest Customer Wealth with a dry run and Java code.