https://leetcode.com/problems/check-array-formation-through-concatenation/description/ Easy

Решение

class Solution {
    fun canFormArray(arr: IntArray, pieces: Array<IntArray>): Boolean {
        val map = HashMap<Int, Int>()
        for ((i, piece) in pieces.withIndex()) {
            map[piece[0]] = i
        }
        var idx = 0
        while (idx < arr.size) {
            val i = map[arr[idx]] ?: return false
            val piece = pieces[i]
            for (num in piece) {
                if (arr[idx++] != num) return false
            }
        }
        return true
    }
}