Practice Form Array by Concatenating Subarrays of Another Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Form Array by Concatenating Subarrays of Another Array
Problem Statement
You are given a 2D integer array groups of length n. You are also given an integer array nums. You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i] (0-indexed), and if i > 0, the (i-1)th subarray appears before the ith subarray in nums (i.e. the subarrays must be in the same order as groups). Return true if you can do this task, and false otherwise. Note that the subarrays are disjoint if and only if there is no index k such that nums[k] belongs to more than one subarray. A subarray is a contiguous sequence of elements within an array.
Source: Form Array by Concatenating Subarrays of Another Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
groups = [[1,-1,-1],[3,-2,0]], nums = [1,-1,0,1,-1,-1,3,-2,0]
true
# Example 2
groups = [[10,-2],[1,2,3,4]], nums = [1,2,3,4,10,-2]
false
# Example 3
groups = [[1,2,3],[3,4]], nums = [7,7,1,2,3,4,7,7]
false
Constraints
Related LeetCode Problems
Practice more problems similar to Form Array by Concatenating Subarrays of Another Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.