Skip to content

Commit 328ab19

Browse files
committedApr 2, 2025
Add solution #2873
1 parent b161280 commit 328ab19

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,111 LeetCode solutions in JavaScript
1+
# 1,112 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1091,6 +1091,7 @@
10911091
2727|[Is Object Empty](./solutions/2727-is-object-empty.js)|Easy|
10921092
2780|[Minimum Index of a Valid Split](./solutions/2780-minimum-index-of-a-valid-split.js)|Medium|
10931093
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|
10941095
2948|[Make Lexicographically Smallest Array by Swapping Elements](./solutions/2948-make-lexicographically-smallest-array-by-swapping-elements.js)|Medium|
10951096
2965|[Find Missing and Repeated Values](./solutions/2965-find-missing-and-repeated-values.js)|Easy|
10961097
3042|[Count Prefix and Suffix Pairs I](./solutions/3042-count-prefix-and-suffix-pairs-i.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)
Please sign in to comment.