Skip to content

1672. Richest Customer Wealth 👍

  • Time: $O(mn)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  int maximumWealth(vector<vector<int>>& accounts) {
    return accumulate(accounts.begin(), accounts.end(), 0,
                      [](int subtotal, const vector<int>& account) {
      return max(subtotal, accumulate(account.begin(), account.end(), 0));
    });
  }
};
1
2
3
4
5
6
7
8
class Solution {
  public int maximumWealth(int[][] accounts) {
    return Arrays.stream(accounts)
        .mapToInt(account -> Arrays.stream(account).sum())
        .max()
        .getAsInt();
  }
}
1
2
3
class Solution:
  def maximumWealth(self, accounts: list[list[int]]) -> int:
    return max(map(sum, accounts))