|
| 1 | +<h2><a href="https://leetcode.com/problems/split-array-into-consecutive-subsequences/">659. Split Array into Consecutive Subsequences</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>nums</code> that is <strong>sorted in non-decreasing order</strong>.</p> |
| 2 | + |
| 3 | +<p>Determine if it is possible to split <code>nums</code> into <strong>one or more subsequences</strong> such that <strong>both</strong> of the following conditions are true:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Each subsequence is a <strong>consecutive increasing sequence</strong> (i.e. each integer is <strong>exactly one</strong> more than the previous integer).</li> |
| 7 | + <li>All subsequences have a length of <code>3</code><strong> or more</strong>.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>Return <code>true</code><em> if you can split </em><code>nums</code><em> according to the above conditions, or </em><code>false</code><em> otherwise</em>.</p> |
| 11 | + |
| 12 | +<p>A <strong>subsequence</strong> of an array is a new array that is formed from the original array by deleting some (can be none) of the elements without disturbing the relative positions of the remaining elements. (i.e., <code>[1,3,5]</code> is a subsequence of <code>[<u>1</u>,2,<u>3</u>,4,<u>5</u>]</code> while <code>[1,3,2]</code> is not).</p> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong>Example 1:</strong></p> |
| 16 | + |
| 17 | +<pre><strong>Input:</strong> nums = [1,2,3,3,4,5] |
| 18 | +<strong>Output:</strong> true |
| 19 | +<strong>Explanation:</strong> nums can be split into the following subsequences: |
| 20 | +[<strong><u>1</u></strong>,<strong><u>2</u></strong>,<strong><u>3</u></strong>,3,4,5] --> 1, 2, 3 |
| 21 | +[1,2,3,<strong><u>3</u></strong>,<strong><u>4</u></strong>,<strong><u>5</u></strong>] --> 3, 4, 5 |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong>Example 2:</strong></p> |
| 25 | + |
| 26 | +<pre><strong>Input:</strong> nums = [1,2,3,3,4,4,5,5] |
| 27 | +<strong>Output:</strong> true |
| 28 | +<strong>Explanation:</strong> nums can be split into the following subsequences: |
| 29 | +[<strong><u>1</u></strong>,<strong><u>2</u></strong>,<strong><u>3</u></strong>,3,<strong><u>4</u></strong>,4,<strong><u>5</u></strong>,5] --> 1, 2, 3, 4, 5 |
| 30 | +[1,2,3,<strong><u>3</u></strong>,4,<strong><u>4</u></strong>,5,<strong><u>5</u></strong>] --> 3, 4, 5 |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p><strong>Example 3:</strong></p> |
| 34 | + |
| 35 | +<pre><strong>Input:</strong> nums = [1,2,3,4,4,5] |
| 36 | +<strong>Output:</strong> false |
| 37 | +<strong>Explanation:</strong> It is impossible to split nums into consecutive increasing subsequences of length 3 or more. |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p> </p> |
| 41 | +<p><strong>Constraints:</strong></p> |
| 42 | + |
| 43 | +<ul> |
| 44 | + <li><code>1 <= nums.length <= 10<sup>4</sup></code></li> |
| 45 | + <li><code>-1000 <= nums[i] <= 1000</code></li> |
| 46 | + <li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li> |
| 47 | +</ul> |
| 48 | +</div> |
0 commit comments