Skip to main content

1672. Richest Customer Wealth

easy

Given an m x n grid where accounts[i][j] is the money customer i has in bank j, return the wealth that the richest customer has. A clean primer on iterating 2D arrays and tracking a running maximum.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Problem

You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i-th customer has in the j-th bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they have in all their bank accounts. The richest customer is the one with the maximum wealth.

Constraints

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

Examples

Example 1

Input
accounts = [[1,2,3],[3,2,1]]
Output
6

Explanation: Customer 1 has wealth = 1+2+3 = 6. Customer 2 has wealth = 3+2+1 = 6. Both customers are considered the richest with a wealth of 6.

Example 2

Input
accounts = [[1,5],[7,3],[3,5]]
Output
10

Explanation: Customer 2 has the maximum wealth = 7 + 3 = 10.

Example 3

Input
accounts = [[2,8,7],[7,1,3],[1,9,5]]
Output
17

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

Hints

Progressive — try the first before opening the next.

Hint 1

Compute the sum of each row, then return the largest such sum.

Hint 2

You do not need an extra array — keep a single 'best so far' variable and update it as you iterate rows.

Hint 3

Early-exit micro-optimisations rarely matter at these constraints; clarity beats cleverness here.

Solution approach

Reveal approach

Iterate over each row of the grid. For each row, compute the sum of its entries (one inner loop), then compare that sum against a running maximum initialised to 0 (or -infinity). After visiting every row, the running maximum is the answer. Since both dimensions are bounded by 50, even the most straightforward double-loop runs comfortably within the limits. The point of the problem is to confirm you handle 2D iteration cleanly without off-by-one errors.

Complexity

Time
O(m * n)
Space
O(1)

Related patterns

  • iteration
  • matrix-traversal

Related problems

Asked at

Companies reported asking this problem (sourced from public Glassdoor, Blind, and Levels.fyi interview posts).

  • Amazon
  • Adobe

Practice these live with InterviewChamp.AI

Drill Richest Customer Wealth and Arrays problems under real interview conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →