You are building a feature-flag system for a product.
There are n features labeled 0 to n - 1. Each dependency pair [a, b] means feature a depends on feature b, so b must be active before a can be activated.
You are also given:
-
a set
active
of features that are already enabled, and
-
a target feature
t
that a user wants to activate.
A feature can be activated only after all of its direct and indirect prerequisites are active. If a prerequisite is not active yet, it must be activated first.
Write a function that returns one valid order of newly activated features needed to enable t.
Rules:
-
Only include features that are not already active.
-
The returned order must activate prerequisites before any dependent feature.
-
If
t
is already active, return an empty list.
-
If
t
cannot be activated because its dependency chain contains a cycle, return
null
.
Example:
-
dependencies = [[3,1],[3,2],[2,0]]
-
active = {1}
-
t = 3
A valid answer is [0,2,3].
Implement this efficiently.