LeetCode · September 19, 2021

Richest Customer Wealth | LeetCode 1672 | Python | Solution

Click here to see the problem details. And read the problem details.

Pretty simple problem. We will receive a 2D array. Where array[i] is the list of ith customer money from the different bank account, and we have to find out the wealthiest customer’s total from the list. After that, we have to return the amount. We only need the maximum amount, don’t need to find the customer.

To solve this problem, first, we will go through each of the customers’ bank lists. And then sum up all the amounts from the different banks of that customer and store the final result in an array.

After storing all the customer’s final amounts in the array, we will return the maximum amount from that array.

Let’s see the solution in Python. I hope you will get a clear idea after that.

class Solution:
    def maximumWealth(self, accounts: List[List[int]]) -> int:
        result = []
        for account in accounts:
        return max(result)

# One Line Solution = max(map(sum, accounts))

I hope you got the idea. I use Python’s built-in function sum and max to solve this problem.
You can solve it differently.