LeetCode solutions

1760. Check Array Formation Through Concatenation

My accepted Python solution to LeetCode problem 1760, Check Array Formation Through Concatenation, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-30.

python
class Solution:
    def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool:
        piece_map = {p[0]: p for p in pieces}
        i = 0
        while i < len(arr):
            if arr[i] not in piece_map:
                return False
            piece = piece_map[arr[i]]
            for val in piece:
                if i >= len(arr) or arr[i] != val:
                    return False
                i += 1
        return True

Source