Find the richest customer's total wealth in a grid of account balances

Quick Overview

Given a grid where each row lists one customer's bank account balances, return the largest total wealth held by any single customer. Tests basic matrix traversal, summing rows, and keeping a running maximum.

Find the richest customer's total wealth in a grid of account balances

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given an `m x n` integer grid called `accounts`, where each row represents a customer and each element in the row is the amount of money they have in one bank account. The wealth of a customer is the total sum of money they have across all their accounts. Return the wealth of the richest customer, that is, the highest total wealth among all customers. ### Function Signature ```python def maximum_wealth(accounts: list[list[int]]) -> int: ``` ### Constraints - `m == accounts.length` - `n == accounts[i].length` - `1 <= m, n <= 75` - `1 <= accounts[i][j] <= 75` ### Examples ```text Input: accounts = [[2, 3, 4], [4, 3, 2]] Output: 9 ``` The first customer has 2 + 3 + 4 = 9 and the second has 4 + 3 + 2 = 9. Both customers have a wealth of 9, so the output is 9. ```text Input: accounts = [[3, 6], [8, 4], [4, 6]] Output: 12 ``` The customers have 3 + 6 = 9, 8 + 4 = 12 and 4 + 6 = 10. The second customer is the richest with a wealth of 12. ```text Input: accounts = [[1, 4, 5], [6, 2, 7], [3, 9, 6]] Output: 18 ``` The customers have 1 + 4 + 5 = 10, 6 + 2 + 7 = 15 and 3 + 9 + 6 = 18. The third customer is the richest with a wealth of 18.

Overview: Given a grid where each row lists one customer's bank account balances, return the largest total wealth held by any single customer. Tests basic matrix traversal, summing rows, and keeping a running maximum.

Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given an m x n integer grid called accounts, where each row represents a customer and each element in the row is the amount of money they have in one bank account. The wealth of a customer is the total sum of money they have across all their accounts.

Return the wealth of the richest customer, that is, the highest total wealth among all customers.

Function Signature

def maximum_wealth(accounts: list[list[int]]) -> int:

Constraints

  • m == accounts.length
  • n == accounts[i].length
  • 1 <= m, n <= 75
  • 1 <= accounts[i][j] <= 75

Examples

Input: accounts = [[2, 3, 4], [4, 3, 2]]
Output: 9

The first customer has 2 + 3 + 4 = 9 and the second has 4 + 3 + 2 = 9. Both customers have a wealth of 9, so the output is 9.

Input: accounts = [[3, 6], [8, 4], [4, 6]]
Output: 12

The customers have 3 + 6 = 9, 8 + 4 = 12 and 4 + 6 = 10. The second customer is the richest with a wealth of 12.

Input: accounts = [[1, 4, 5], [6, 2, 7], [3, 9, 6]]
Output: 18

The customers have 1 + 4 + 5 = 10, 6 + 2 + 7 = 15 and 3 + 9 + 6 = 18. The third customer is the richest with a wealth of 18.