You get a grid where each row is one customer, and each cell is the money in one bank account. A customer's wealth is the sum of their row. Return the wealth of the richest customer.
DSA Animator › DSA Revision › Arrays › Richest Customer Wealth
Remember: row sums plus a running maximum. In a 2D grid, the outer loop picks the row, and the inner loop walks its columns. The video solves Richest Customer Wealth (LeetCode 1672, Easy) with the 2D Array pattern from the Arrays topic, and you can replay every step in the interactive Richest Customer Wealth animation.
You get a grid where each row is one customer, and each cell is the money in one bank account. A customer's wealth is the sum of their row. Return the wealth of the richest customer.
For rows 1 and 5, 7 and 3, and 3 and 5, the wealths are 6, 10 and 8. The richest has 10.
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.
Start with best equal to 0. Row 0 is 1 plus 5, which is 6, so best becomes 6. Row 1 is 7 plus 3, which is 10, so best becomes 10. Row 2 is 3 plus 5, which is 8, which is less than 10. The richest customer has 10.
In code, keep a best of 0. For each row, add up its accounts. Then update best with the larger value. Every cell is read once, so it's O of m times n time, and O of 1 space.
Remember: row sums plus a running maximum. In a 2D grid, the outer loop picks the row, and the inner loop walks its columns.