File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,111 LeetCode solutions in JavaScript
1
+ # 1,112 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1091
1091
2727|[ Is Object Empty] ( ./solutions/2727-is-object-empty.js ) |Easy|
1092
1092
2780|[ Minimum Index of a Valid Split] ( ./solutions/2780-minimum-index-of-a-valid-split.js ) |Medium|
1093
1093
2818|[ Apply Operations to Maximize Score] ( ./solutions/2818-apply-operations-to-maximize-score.js ) |Hard|
1094
+ 2873|[ Maximum Value of an Ordered Triplet I] ( ./solutions/2873-maximum-value-of-an-ordered-triplet-i.js ) |Easy|
1094
1095
2948|[ Make Lexicographically Smallest Array by Swapping Elements] ( ./solutions/2948-make-lexicographically-smallest-array-by-swapping-elements.js ) |Medium|
1095
1096
2965|[ Find Missing and Repeated Values] ( ./solutions/2965-find-missing-and-repeated-values.js ) |Easy|
1096
1097
3042|[ Count Prefix and Suffix Pairs I] ( ./solutions/3042-count-prefix-and-suffix-pairs-i.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2873. Maximum Value of an Ordered Triplet I
3
+ * https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given a 0-indexed integer array nums.
7
+ *
8
+ * Return the maximum value over all triplets of indices (i, j, k) such that i < j < k.
9
+ * If all such triplets have a negative value, return 0.
10
+ *
11
+ * The value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].
12
+ */
13
+
14
+ /**
15
+ * @param {number[] } nums
16
+ * @return {number }
17
+ */
18
+ var maximumTripletValue = function ( nums ) {
19
+ let result = 0 ;
20
+
21
+ for ( let i = 0 ; i < nums . length - 2 ; i ++ ) {
22
+ for ( let j = i + 1 ; j < nums . length - 1 ; j ++ ) {
23
+ const diff = nums [ i ] - nums [ j ] ;
24
+ if ( diff <= 0 ) continue ;
25
+ for ( let k = j + 1 ; k < nums . length ; k ++ ) {
26
+ result = Math . max ( result , diff * nums [ k ] ) ;
27
+ }
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments