Richest Customer Wealth - Problem
You are given an m x n integer matrix accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank.
Return the wealth of the richest customer.
A customer's wealth is the sum of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
Input & Output
Example 1 — Equal Wealth
$
Input:
accounts = [[1,2,3],[3,2,1]]
›
Output:
6
💡 Note:
Customer 1 has wealth = 1+2+3 = 6. Customer 2 has wealth = 3+2+1 = 6. Both customers have equal wealth of 6.
Example 2 — Different Wealth
$
Input:
accounts = [[1,5],[7,3],[3,5]]
›
Output:
10
💡 Note:
Customer 1: 1+5 = 6, Customer 2: 7+3 = 10, Customer 3: 3+5 = 8. The richest customer has wealth = 10.
Example 3 — Single Account
$
Input:
accounts = [[2,8,7],[7,1,3],[1,9,5]]
›
Output:
17
💡 Note:
Customer 1: 2+8+7 = 17, Customer 2: 7+1+3 = 11, Customer 3: 1+9+5 = 15. Maximum wealth is 17.
Constraints
- 1 ≤ m, n ≤ 50
- 1 ≤ accounts[i][j] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Matrix
Each row represents a customer, each column a bank account
2
Calculate Sums
Sum each customer's accounts to get their total wealth
3
Find Maximum
Return the highest wealth among all customers
Key Takeaway
🎯 Key Insight: Sum each customer's accounts and track the maximum wealth encountered
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code