Skip to content

Commit fc4c43b

Browse files
authored
Create 2873. Maximum Value of an Ordered Triplet I (#759)
2 parents da4e088 + ac50853 commit fc4c43b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: 2873. Maximum Value of an Ordered Triplet I

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
long long maximumTripletValue(vector<int>& nums) {
4+
int n=nums.size();
5+
long long max_i=nums[0];
6+
long long max_diff=nums[0]-nums[1];
7+
long long ans=0;
8+
for(int k=2;k<n;k++){
9+
ans=max(ans,max_diff*nums[k]);
10+
max_i=max(max_i,(long long)nums[k-1]);
11+
max_diff=max(max_diff,max_i-nums[k]);
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)