Richest Customer Wealth
Row Sum + Running Max
Asked at 5 companies
3 recent
- Microsoft
- Amazon
- Meta
- Bloomberg
Community-reported · source · updated 2026-11-18. ● asked in the last 6 months.
Go step by step: try it yourself before the video and the visual. Progress saves on this device.
0 / 110 pointsSolved (Easy) 0/20Reviews 0/50Mastered 0/25Practice steps 0/15
Step 1
Know these before you start
Practise each one here, or tick what you already know
Watch the concept video if the pattern is new to you.
Step 2
Try it on paper
5–10 minutes, no code yet
ProblemProblem statementYou are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank.ReadHide
Problem Statement
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank.
Return the wealth that the richest customer has. A customer's wealth is the total amount of money they have in all their bank accounts.
Input / Output
Input: accounts = [[1,2,3],[3,2,1]]
Output: 6
Explanation: Both customers have wealth 6.
Input: accounts = [[1,5],[7,3],[3,5]]
Output: 10
Input: accounts = [[2,8,7],[7,1,3],[1,9,5]]
Output: 17
Constraints
m == accounts.length
n == accounts[i].length
1 ≤ m, n ≤ 50
1 ≤ accounts[i][j] ≤ 100
Understanding the Problem
- Each row is one customer → wealth = sum of that row
- Answer = maximum row sum
Edge Cases
- Single customer → their row sum
- All customers equal → any row sum
Code it here
Tab / Shift+Tab indent · ⌘/Ctrl+/ comments · ⌘/Ctrl+Enter runs · Esc leaves the editor
Step 6
Get it accepted
All test cases pass
Step 7
Review it so it sticks
Re-solve from memory after
The step that matters most: without reviews most of a solved problem fades within weeks. Three short re-solves, each just as you start to forget, are what make it yours.
Your notes
Three lines in your own words. They come back with this problem's reviews, so you can check yourself after recalling the solution.
Solve it yourself before you look
Reading the solution first feels like progress, but it makes the next similar problem — and the interview version — much harder, because you skipped the part where you figure it out. Give it an honest 20–30 minutes. Stuck? Re-read the pattern, watch the concept video, or try the brute force first.
Hidden: approach · solution code · optimal solution
Approach
Pattern Recognition
Row Sum + Running Max — reduce each row to one number, then track the best seen so far.
Approach
Brute Force — O(m × n) time | O(m) space
Compute every row sum into a list
Return max(list)
Optimized — O(m × n) time | O(1) space
best = 0
For each row:
wealth = sum(row)
best = max(best, wealth)
Return best
Complexity
| Approach | Time | Space | Notes |
|---|---|---|---|
| Brute Force | O(m × n) | O(m) | Stores all row sums |
| Optimized | O(m × n) | O(1) | Running max, no extra storage |
Online Compiler
Solution code
import sys
input = sys.stdin.readline
# ─────────────────────────────────────────────────────────────────────────
# OPTIMIZED — O(m × n) time | O(1) space
# Sum each row, keep a running max
# ─────────────────────────────────────────────────────────────────────────
def maximum_wealth(accounts):
best = 0 # richest wealth so far
for customer in accounts:
wealth = sum(customer) # total for this customer
best = max(best, wealth) # update running max
return best
# ── Pythonic alternative (same complexity) ───────────────────────────────
def maximum_wealth_pythonic(accounts):
return max(map(sum, accounts))
# ── Input ─────────────────────────────────────────────────────────────────
m, n = map(int, input().split())
accounts = [list(map(int, input().split())) for _ in range(m)]
print(maximum_wealth(accounts))Other ways to solve it
- Thought of another approach (slower, or cleverer)? Code it here: the same tests check any approach.
- Community solutions on LeetCode ↗ for many more versions, in many languages. Read them after you've solved it.
Revising this one?
- →Solve it from memory before peeking
- →Say the pattern out loud, not just the code
- →Explain it like you would to a friend
- →Try it again in a different language