1764. Form Array by Concatenating Subarrays of Another Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1764

class Solution:
    def canChoose(self, groups: List[List[int]], nums: List[int]) -> bool:
        n, m = len(groups), len(nums)
        i = j = 0
        while i < n and j < m:
            g = groups[i]
            if g == nums[j : j + len(g)]:
                j += len(g)
                i += 1
            else:
                j += 1
        return i == n