Richest Customer Wealth

PHOTO EMBED

Thu Jul 18 2024 08:05:58 GMT+0000 (Coordinated Universal Time)

Saved by @Mohanish

public class RichestCustomerWealth  {
    public static void main(String[] args) {
        int[][] accounts = {
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };
        System.out.println(CustomerWealth(accounts));

    }
    public static int CustomerWealth(int[][] accounts) {
        //person =ro
        //account=col
        int ans=Integer.MIN_VALUE;

        for (int person = 0; person < accounts.length; person++) {
            //when you start a new col ,take a new row
            int sum=0;
            for (int account = 0; account < accounts[person].length; account++) {
                sum = sum + accounts[person][account];
            }
            //now we have sum of accounts of person
            //check overall ans
            if (sum > ans) {
                ans = sum;
            }
        }
        return ans;
    }

}
content_copyCOPY