All problems
Precedence Constraints Check
Problem
Check whether a proposed task order satisfies all precedence constraints.
Each constraint [a, b] means task a must appear before task b in order. Return False when a task is missing from order or when some constraint is violated. order is a permutation of task labels.
Hint
Map each task to its position once, then compare positions for every constraint.
Test cases
case 1
in: [[0,1,2],[[0,1],[1,2]]]
expected: true
case 2
in: [[2,1,0],[[0,1]]]
expected: false
case 3
in: [[1,0],[]]
expected: true
case 4
in: [[0,1],[[0,1],[1,0]]]
expected: false
case 5
in: [[1,2,0],[[0,2]]]
expected: false
Starter codePython
def precedence_feasible(order, constraints):
# Your code here
pass5 test cases · run your code against them in the editor