1640. Check Array Formation Through Concatenation Easy
1/**
2 * [1640] Check Array Formation Through Concatenation
3 *
4 * You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i].
5 * Return true if it is possible to form the array arr from pieces. Otherwise, return false.
6 *
7 * Example 1:
8 *
9 * Input: arr = [15,88], pieces = [[88],[15]]
10 * Output: true
11 * Explanation: Concatenate [15] then [88]
12 *
13 * Example 2:
14 *
15 * Input: arr = [49,18,16], pieces = [[16,18,49]]
16 * Output: false
17 * Explanation: Even though the numbers match, we cannot reorder pieces[0].
18 *
19 * Example 3:
20 *
21 * Input: arr = [91,4,64,78], pieces = [[78],[4,64],[91]]
22 * Output: true
23 * Explanation: Concatenate [91] then [4,64] then [78]
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= pieces.length <= arr.length <= 100
29 * sum(pieces[i].length) == arr.length
30 * 1 <= pieces[i].length <= arr.length
31 * 1 <= arr[i], pieces[i][j] <= 100
32 * The integers in arr are distinct.
33 * The integers in pieces are distinct (i.e., If we flatten pieces in a 1D array, all the integers in this array are distinct).
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/check-array-formation-through-concatenation/
39// discuss: https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn can_form_array(arr: Vec<i32>, pieces: Vec<Vec<i32>>) -> bool {
45 false
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1640() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.