order is a permutation of the numbers 1 to n. You also get a set of fragments fragments: each fragment is a subsequence of order, that is, some of its numbers in the same relative order (not necessarily adjacent).
Call a sequence fitting if every fragment is a subsequence of it. Among all fitting sequences, look at the shortest ones.
Return True if order is the one and only shortest fitting sequence, and False otherwise.order=[2, 1, 3], fragments=[[2, 1], [1, 3]] → True
The fragments chain into 2 → 1 → 3 with no other option, so the answer is True.
order=[2, 1, 3], fragments=[[2, 1], [2, 3]] → False
All we know is that 2 comes before both 1 and 3. The order [2, 3, 1] fits just as well, so the answer is False.
order=[1, 2, 3, 4], fragments=[[1, 2, 3]] → False
The number 4 appears in no fragment, so the shortest fitting sequence is [1, 2, 3], not order. The answer is False.
n == order.lengthn ≤ 10⁴order is a permutation of the numbers 1 to nfragments.length ≤ 10⁴fragments[i].length ≤ 10⁴fragments[i] is a subsequence of orderorder=[2, 1, 3], fragments=[[2, 1], [1, 3]]
True
Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.