Richest Customer Wealth · Optimal Solution

Sum each row. Keep the maximum.

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.


Interactive

Watch row sums accumulate


Concept

Row = Customer, Sum = Wealth

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.


Algorithm

Two nested loops

A nested loop sums each customer's balances, keeping track of the running maximum. Every cell is visited exactly once.

  1. 1

    Initialize maximum

    Set richest = 0. No customer has been evaluated yet.

  2. 2

    Sum each row

    For each customer (row), compute the sum of all bank balances in that row.

  3. 3

    Track maximum

    If the current row sum exceeds richest, update it. After all rows, richest holds the answer.


Edge Cases

Edge patterns

Understanding boundary behavior is as important as the main algorithm path.

Single customer

The matrix has one row. The sum of that row is the answer — no comparison needed.

Single bank

Each customer has one account. The problem reduces to finding the maximum element.