Skip to content

Commit b3d120a

Browse files
joshua-dierickse-altiWolf22
authored andcommitted
Added README.md file for Constrained Subsequence Sum
Co-authored-by: Joshua Dierickse <joshua.dierickse@gmail.com>
1 parent 61cbbc8 commit b3d120a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<h2><a href="https://leetcode.com/problems/constrained-subsequence-sum">Constrained Subsequence Sum</a></h2> <img src='https://img.shields.io/badge/Difficulty-Hard-red' alt='Difficulty: Hard' /><hr><p>Given an integer array <code>nums</code> and an integer <code>k</code>, return the maximum sum of a <strong>non-empty</strong> subsequence of that array such that for every two <strong>consecutive</strong> integers in the subsequence, <code>nums[i]</code> and <code>nums[j]</code>, where <code>i &lt; j</code>, the condition <code>j - i &lt;= k</code> is satisfied.</p>
2+
3+
<p>A <em>subsequence</em> of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> nums = [10,2,-10,5,20], k = 2
10+
<strong>Output:</strong> 37
11+
<b>Explanation:</b> The subsequence is [10, 2, 5, 20].
12+
</pre>
13+
14+
<p><strong class="example">Example 2:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [-1,-2,-3], k = 1
18+
<strong>Output:</strong> -1
19+
<b>Explanation:</b> The subsequence must be non-empty, so we choose the largest number.
20+
</pre>
21+
22+
<p><strong class="example">Example 3:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> nums = [10,-2,-10,-5,20], k = 2
26+
<strong>Output:</strong> 23
27+
<b>Explanation:</b> The subsequence is [10, -2, -5, 20].
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Constraints:</strong></p>
32+
33+
<ul>
34+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
35+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
36+
</ul>

0 commit comments

Comments
 (0)