File: richest-customer-wealth/solution.py

Date: 2026-06-06

Time: 18:55

richest-customer-wealth/solution.py

Purpose

This file solves LeetCode 1672 — Richest Customer Wealth. It owns exactly one responsibility: given a 2D grid of bank account balances, find the customer with the highest total wealth and return that amount.

Key Components

Solution.maximumWealth(self, accounts: List[List[int]]) -> int — The sole method. Takes an m x n matrix where accounts[i][j] represents how much money customer i holds in bank j. Returns the maximum row-sum across all rows.

The implementation is a single expression: max(sum(row) for row in accounts). It uses a generator expression to lazily compute each customer's total wealth (sum(row)), then max() selects the largest.

Patterns

Dependencies

Imports: typing.List — used only for the type annotation. At runtime, the code depends on nothing beyond builtins (max, sum).

Imported by: The test file richest-customer-wealth/test_solution.py imports this Solution class. The massive "Imported By" list in the prompt is misleading — those are test files from *other* problems that happen to share the same from solution import Solution pattern, not actual consumers of this specific file.

Flow

1. The generator (sum(row) for row in accounts) iterates over each row (customer).

2. For each row, sum(row) computes the total across all banks.

3. max(...) consumes the generator and returns the largest total.

No intermediate data structure is allocated — the generator yields one integer at a time.

Invariants

Error Handling

None. The code trusts its caller (LeetCode's judge) to provide valid input. An empty accounts list would crash with ValueError from max(), and non-numeric values would crash inside sum(). Both are impossible under the problem constraints.

Complexity

Topics to Explore

Beliefs