Single customer
The matrix has one row. The sum of that row is the answer — no comparison needed.
A private bank ranks clients by total holdings spread across multiple accounts. Each row of the ledger represents one client; each column a different account. The teller sums every row and tracks the running maximum — the wealthiest client's total emerges after a single pass over the matrix. O(m × n) time. O(1) extra space.
Each row of the matrix represents one customer's portfolio. The column index identifies which bank holds that balance. Summing across a row gives total wealth for that customer. The richest customer is the one whose row sum is largest.
A nested loop sums each customer's balances, keeping track of the running maximum. Every cell is visited exactly once.
Set richest = 0. No customer has been evaluated yet.
For each customer (row), compute the sum of all bank balances in that row.
If the current row sum exceeds richest, update it. After all rows, richest holds the answer.
Understanding boundary behavior is as important as the main algorithm path.
The matrix has one row. The sum of that row is the answer — no comparison needed.
Each customer has one account. The problem reduces to finding the maximum element.