3468. Find the Number of Copy Arrays Medium

@problem@discussion
#Array#Math



1/**
2 * [3468] Find the Number of Copy Arrays
3 *
4 * You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [ui, vi].
5 * You need to find the number of possible arrays copy of length n such that:
6 * <ol>
7 * 	(copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1.
8 * 	ui <= copy[i] <= vi for 0 <= i <= n - 1.
9 * </ol>
10 * Return the number of such arrays.
11 *  
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">original = [1,2,3,4], bounds = [[1,2],[2,3],[3,4],[4,5]]</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:
17 * The possible arrays are:
18 * 
19 * 	[1, 2, 3, 4]
20 * 	[2, 3, 4, 5]
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">original = [1,2,3,4], bounds = [[1,10],[2,9],[3,8],[4,7]]</span>
25 * Output: <span class="example-io">4</span>
26 * Explanation:
27 * The possible arrays are:
28 * 
29 * 	[1, 2, 3, 4]
30 * 	[2, 3, 4, 5]
31 * 	[3, 4, 5, 6]
32 * 	[4, 5, 6, 7]
33 * </div>
34 * <strong class="example">Example 3:
35 * <div class="example-block">
36 * Input: <span class="example-io">original = [1,2,1,2], bounds = [[1,1],[2,3],[3,3],[2,3]]</span>
37 * Output: <span class="example-io">0</span>
38 * Explanation:
39 * No array is possible.
40 * </div>
41 *  
42 * Constraints:
43 * 
44 * 	2 <= n == original.length <= 10^5
45 * 	1 <= original[i] <= 10^9
46 * 	bounds.length == n
47 * 	bounds[i].length == 2
48 * 	1 <= bounds[i][0] <= bounds[i][1] <= 10^9
49 * 
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/find-the-number-of-copy-arrays/
54// discuss: https://leetcode.com/problems/find-the-number-of-copy-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59    pub fn count_arrays(original: Vec<i32>, bounds: Vec<Vec<i32>>) -> i32 {
60        0
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_3468() {
72    }
73}
74

Back
© 2026 bowen.ge All Rights Reserved.