Skip to content

Commit e41c069

Browse files
2874_Maximum_Value_of_an_Ordered_Triplet_II.java
1 parent aba841c commit e41c069

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Problem Number: 2874.
2+
3+
// Maximum Value of an Ordered Triplet II.
4+
5+
class Solution {
6+
public long maximumTripletValue(int[] nums) {
7+
long ans = 0;
8+
int maxDiff = 0;
9+
int maxNum = 0;
10+
11+
for (final int num : nums) {
12+
ans = Math.max(ans, (long) maxDiff * num);
13+
maxDiff = Math.max(maxDiff, maxNum - num);
14+
maxNum = Math.max(maxNum, num);
15+
}
16+
17+
return ans;
18+
}
19+
}

0 commit comments

Comments
 (0)