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
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. Find the <strong>largest even sum</strong> of any subsequence of <code>nums</code> that has a length of <code>k</code>.</p>
10
+
11
+
<p>Return <em>this sum, or </em><code>-1</code><em> if such a sum does not exist</em>.</p>
12
+
13
+
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
14
+
15
+
<p> </p>
16
+
<p><strong>Example 1:</strong></p>
17
+
18
+
<pre>
19
+
<strong>Input:</strong> nums = [4,1,5,3,1], k = 3
20
+
<strong>Output:</strong> 12
21
+
<strong>Explanation:</strong>
22
+
The subsequence with the largest possible even sum is [4,5,3]. It has a sum of 4 + 5 + 3 = 12.
23
+
</pre>
24
+
25
+
<p><strong>Example 2:</strong></p>
26
+
27
+
<pre>
28
+
<strong>Input:</strong> nums = [4,6,2], k = 3
29
+
<strong>Output:</strong> 12
30
+
<strong>Explanation:</strong>
31
+
The subsequence with the largest possible even sum is [4,6,2]. It has a sum of 4 + 6 + 2 = 12.
32
+
</pre>
33
+
34
+
<p><strong>Example 3:</strong></p>
35
+
36
+
<pre>
37
+
<strong>Input:</strong> nums = [1,3,5], k = 1
38
+
<strong>Output:</strong> -1
39
+
<strong>Explanation:</strong>
40
+
No subsequence of nums with length 1 has an even sum.
0 commit comments