Richest Customer Wealth — LeetCode 1672 Python Solution

EasyArrayMatrix
Problem
#1672
Reading time
2 min

The 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.

Example

Input
accounts = [[1,2,3],[3,2,1]]
Output
6
Explanation
1st customer has wealth = 1 + 2 + 3 = 6

Python solution

Python
class Solution:
    def maximumWealth(self, accounts: List[List[int]]) -> int:
        return max(sum(v) for v in accounts)

Complexity

MeasureComplexity
TimeO(m \times n), where m and n are the number of rows and columns in the grid, respectively
SpaceO(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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview