|
| 1 | +<h2><a href="https://leetcode.com/problems/arithmetic-slices-ii-subsequence/">446. Arithmetic Slices II - Subsequence</a></h2><h3>Hard</h3><hr><div><p>Given an integer array <code>nums</code>, return <em>the number of all the <strong>arithmetic subsequences</strong> of</em> <code>nums</code>.</p> |
| 2 | + |
| 3 | +<p>A sequence of numbers is called arithmetic if it consists of <strong>at least three elements</strong> and if the difference between any two consecutive elements is the same.</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>For example, <code>[1, 3, 5, 7, 9]</code>, <code>[7, 7, 7, 7]</code>, and <code>[3, -1, -5, -9]</code> are arithmetic sequences.</li> |
| 7 | + <li>For example, <code>[1, 1, 2, 5, 7]</code> is not an arithmetic sequence.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>A <strong>subsequence</strong> of an array is a sequence that can be formed by removing some elements (possibly none) of the array.</p> |
| 11 | + |
| 12 | +<ul> |
| 13 | + <li>For example, <code>[2,5,10]</code> is a subsequence of <code>[1,2,1,<strong><u>2</u></strong>,4,1,<u><strong>5</strong></u>,<u><strong>10</strong></u>]</code>.</li> |
| 14 | +</ul> |
| 15 | + |
| 16 | +<p>The test cases are generated so that the answer fits in <strong>32-bit</strong> integer.</p> |
| 17 | + |
| 18 | +<p> </p> |
| 19 | +<p><strong class="example">Example 1:</strong></p> |
| 20 | + |
| 21 | +<pre><strong>Input:</strong> nums = [2,4,6,8,10] |
| 22 | +<strong>Output:</strong> 7 |
| 23 | +<strong>Explanation:</strong> All arithmetic subsequence slices are: |
| 24 | +[2,4,6] |
| 25 | +[4,6,8] |
| 26 | +[6,8,10] |
| 27 | +[2,4,6,8] |
| 28 | +[4,6,8,10] |
| 29 | +[2,4,6,8,10] |
| 30 | +[2,6,10] |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p><strong class="example">Example 2:</strong></p> |
| 34 | + |
| 35 | +<pre><strong>Input:</strong> nums = [7,7,7,7,7] |
| 36 | +<strong>Output:</strong> 16 |
| 37 | +<strong>Explanation:</strong> Any subsequence of this array is arithmetic. |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p> </p> |
| 41 | +<p><strong>Constraints:</strong></p> |
| 42 | + |
| 43 | +<ul> |
| 44 | + <li><code>1 <= nums.length <= 1000</code></li> |
| 45 | + <li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li> |
| 46 | +</ul> |
| 47 | +</div> |
0 commit comments