-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem no. 1672.java
37 lines (32 loc) · 973 Bytes
/
Problem no. 1672.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Ques: 1672. Richest Customer Wealth
// Ques Link - https://leetcode.com/problems/richest-customer-wealth/
package com.nitin;
public class MaxWealth {
public static void main(String[] args) {
int[][] accounts = {
{1, 3, 3},
{4, 3, 2}
};
// maximumWealth(accounts);
System.out.println("Maximum wealth is " + maximumWealth(accounts));
}
public static int maximumWealth(int[][] accounts) {
// accounts = col
// person = row
int ans = Integer.MIN_VALUE;
for (int[] ints : accounts) {
int sum = 0;
for (int anInt : ints) {
sum += anInt;
}
// now we have sum of accounts of person
// check with overall ans
if (sum > ans) {
ans = sum;
}
}
// we can take out here as well
System.out.println(ans);
return ans;
}
}