You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2800-2899/2873.Maximum Value of an Ordered Triplet I/README_EN.md
+56-2
Original file line number
Diff line number
Diff line change
@@ -47,12 +47,25 @@ It can be shown that there are no ordered triplets of indices with a value great
47
47
48
48
## Solutions
49
49
50
+
**Solution 1: Maintain Maximum Prefix Value and Maximum Difference**
51
+
52
+
We can use two variables $mx$ and $mx\_diff$ to maintain the maximum prefix value and maximum difference, respectively. When traversing the array, we update these two variables, and the answer is the maximum value of all $mx\_diff \times nums[i]$.
53
+
54
+
The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)$.
Copy file name to clipboardexpand all lines: solution/2800-2899/2874.Maximum Value of an Ordered Triplet II/README_EN.md
+56-2
Original file line number
Diff line number
Diff line change
@@ -47,12 +47,25 @@ It can be shown that there are no ordered triplets of indices with a value great
47
47
48
48
## Solutions
49
49
50
+
**Solution 1: Maintain Maximum Prefix Value and Maximum Difference**
51
+
52
+
We can use two variables $mx$ and $mx\_diff$ to maintain the maximum prefix value and maximum difference, respectively. When traversing the array, we update these two variables, and the answer is the maximum value of all $mx\_diff \times nums[i]$.
53
+
54
+
The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)$.
0 commit comments