Skip to content

Commit 21960ed

Browse files
joshua-dierickse-altiWolf22
authored andcommitted
Added README.md file for Number of Stable Subsequences
Co-authored-by: Joshua Dierickse <joshua.dierickse@gmail.com>
1 parent af2bbde commit 21960ed

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-stable-subsequences">Number of Stable Subsequences</a></h2> <img src='https://img.shields.io/badge/Difficulty-Hard-red' alt='Difficulty: Hard' /><hr><p>You are given an integer array <code>nums</code>.</p>
2+
3+
<p>A <strong><span data-keyword="subsequence-array-nonempty">subsequence</span></strong> is <strong>stable</strong> if it does not contain <strong>three consecutive</strong> elements with the <strong>same</strong> parity when the subsequence is read <strong>in order</strong> (i.e., consecutive <strong>inside the subsequence</strong>).</p>
4+
5+
<p>Return the number of stable subsequences.</p>
6+
7+
<p>Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<div class="example-block">
13+
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,5]</span></p>
14+
15+
<p><strong>Output:</strong> <span class="example-io">6</span></p>
16+
17+
<p><strong>Explanation:</strong></p>
18+
19+
<ul>
20+
<li>Stable subsequences are <code>[1]</code>, <code>[3]</code>, <code>[5]</code>, <code>[1, 3]</code>, <code>[1, 5]</code>, and <code>[3, 5]</code>.</li>
21+
<li>Subsequence <code>[1, 3, 5]</code> is not stable because it contains three consecutive odd numbers. Thus, the answer is 6.</li>
22+
</ul>
23+
</div>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<div class="example-block">
28+
<p><strong>Input:</strong> <span class="example-io">nums = </span>[2,3,4,2]</p>
29+
30+
<p><strong>Output:</strong> <span class="example-io">14</span></p>
31+
32+
<p><strong>Explanation:</strong></p>
33+
34+
<ul>
35+
<li>The only subsequence that is not stable is <code>[2, 4, 2]</code>, which contains three consecutive even numbers.</li>
36+
<li>All other subsequences are stable. Thus, the answer is 14.</li>
37+
</ul>
38+
</div>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>​​​​​​​5</sup></code></li>
46+
</ul>

0 commit comments

Comments
 (0)