Richest Customer Wealth — LeetCode 1672 Python Solution
- Problem
- #1672
- Pattern
- Matrix and Grid
- Reading time
- 2 min
- Source
- leetcode.com
The problem
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.
Example
- Input
- accounts = [[1,2,3],[3,2,1]]
- Output
- 6
- Explanation
- 1st customer has wealth = 1 + 2 + 3 = 6
Python solution
class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
return max(sum(v) for v in accounts)Complexity
| Measure | Complexity |
|---|---|
| Time | O(m \times n), where m and n are the number of rows and columns in the grid, respectively |
| Space | O(1) auxiliary |
Pattern: Matrix and Grid
Treat a 2-D grid as a graph whose neighbours are the four adjacent cells. LeetCode 1672. Richest Customer Wealth is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Matrix.
The matrix and grid guide has the Python template for the pattern and the 216 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1672. Richest Customer Wealth?
- LeetCode 1672. Richest Customer Wealth is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1672. Richest Customer Wealth?
- The Python solution on this page runs in O(m \times n), where m and n are the number of rows and columns in the grid, respectively.
- What is the space complexity of LeetCode 1672. Richest Customer Wealth?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 1672. Richest Customer Wealth cover?
- LeetCode 1672. Richest Customer Wealth is tagged Array and Matrix on LeetCode.