mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 00:11:41 +08:00
71 lines
2.2 KiB
HTML
71 lines
2.2 KiB
HTML
<p>You are given an array <code>original</code> of length <code>n</code> and a 2D array <code>bounds</code> of length <code>n x 2</code>, where <code>bounds[i] = [u<sub>i</sub>, v<sub>i</sub>]</code>.</p>
|
|
|
|
<p>You need to find the number of <strong>possible</strong> arrays <code>copy</code> of length <code>n</code> such that:</p>
|
|
|
|
<ol>
|
|
<li><code>(copy[i] - copy[i - 1]) == (original[i] - original[i - 1])</code> for <code>1 <= i <= n - 1</code>.</li>
|
|
<li><code>u<sub>i</sub> <= copy[i] <= v<sub>i</sub></code> for <code>0 <= i <= n - 1</code>.</li>
|
|
</ol>
|
|
|
|
<p>Return the number of such arrays.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">original = [1,2,3,4], bounds = [[1,2],[2,3],[3,4],[4,5]]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The possible arrays are:</p>
|
|
|
|
<ul>
|
|
<li><code>[1, 2, 3, 4]</code></li>
|
|
<li><code>[2, 3, 4, 5]</code></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">original = [1,2,3,4], bounds = [[1,10],[2,9],[3,8],[4,7]]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>The possible arrays are:</p>
|
|
|
|
<ul>
|
|
<li><code>[1, 2, 3, 4]</code></li>
|
|
<li><code>[2, 3, 4, 5]</code></li>
|
|
<li><code>[3, 4, 5, 6]</code></li>
|
|
<li><code>[4, 5, 6, 7]</code></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">original = [1,2,1,2], bounds = [[1,1],[2,3],[3,3],[2,3]]</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>No array is possible.</p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= n == original.length <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= original[i] <= 10<sup>9</sup></code></li>
|
|
<li><code>bounds.length == n</code></li>
|
|
<li><code>bounds[i].length == 2</code></li>
|
|
<li><code>1 <= bounds[i][0] <= bounds[i][1] <= 10<sup>9</sup></code></li>
|
|
</ul>
|