1672. Richest Customer Wealth

Solution

class Solution {
public:
    int maximumWealth(vector<vector<int>>& accounts) {
        int max = 0;
        
        for (int i = 0; i < accounts.size(); i++) {
            int sum = 0;
            for (int j = 0; j < accounts[i].size(); j++) {
                sum += accounts[i][j];
            }
            if (sum > max) {
                max = sum;
            }
        }
        
        return max;
    }
};

Complexity

  • Time Complexity: O(M*N), where N and M are the number of customers and banks respectively.
  • Space Complexity: O(1).

All Solutions