Trains the technique from
LeetCode 444Sequence ReconstructionThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A festival keeps a master running order nums, which lists every act exactly once. Act numbers run from 1 to n, where n is the length of nums.
sequences holds fragments recovered from old posters. A running order agrees with a fragment when every act the fragment names appears in the running order and the fragment's acts appear in that same relative order, though not necessarily next to each other.
Return true when nums is the only running order of the acts 1 through n that agrees with every fragment, and false otherwise.
Example 1
The running order [1, 3, 2] also agrees with both fragments, since 1 comes before 2 in it and 1 comes before 3, so [1, 2, 3] is not the only one.
Example 2
Together the fragments put 1 before 2, 1 before 3 and 2 before 3, and [1, 2, 3] is the only running order of the three acts that does all of that.
Example 3
The fragment puts act 2 before act 1, which the running order [1, 2] contradicts, so [1, 2] does not agree with the fragment at all.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def only_one_running_order(nums: list[int], sequences: list[list[int]]) -> bool:public boolean onlyOneRunningOrder(int[] nums, List<List<Integer>> sequences)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.