← Questions
Order feature activations by their dependencies
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's HackerRank assessment, last asked Jan 2026. It tests graphs and topological sort.
A product turns on features one at a time. Some features depend on others: a feature can be activated only after every feature it depends on is active. Given the features and their dependencies, return an order to activate all of them, or report that no order exists because the dependencies form a cycle.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
activation_order(features: list[str], depends_on: dict[str, list[str]]) -> list[str]— returns a valid order, or[]if there is a cycle. When several features are ready at once, take them in alphabetical order so the answer is deterministic.
Example
features = ["search", "auth", "billing", "export"]
depends_on = {"billing": ["auth"], "export": ["billing", "search"]}
-> ["auth", "billing", "search", "export"]
features = ["a", "b"]
depends_on = {"a": ["b"], "b": ["a"]}
-> []
Constraints
- Up to 10^5 features and dependencies.
- A dependency may name a feature that is not in
features; agree how to treat it.
Clarifying questions
- Is any valid order fine, or is there a tie-break rule?
- What should happen with a dependency on an unknown feature?
- Should I report which features are on the cycle?
- Can a feature depend on itself?
What a strong answer covers
- Modelling it as a directed graph and finding a topological order.
- Kahn's algorithm: in-degree counts, a queue (or a min-heap for alphabetical ties) of features with no unmet dependencies; a cycle exists if fewer than all features come out. O(V + E), or O(V log V + E) with the heap.
- The DFS alternative with three colours, which also finds the cycle.
- Tests: no dependencies, a chain, a diamond, a cycle, a self-dependency.
Follow-ups
- Return the features on one cycle so an engineer can fix it.
- Activate features in parallel waves: the fewest rounds, and which features go in each.
- Turning a feature off must first turn off everything that depends on it.
Where it's asked
- Google · HackerRank assessment · Last asked Jan 202690 min · Two problems on HackerRank · Some early-career assessments enable the built-in assistant; others forbid AI. The invitation says which.
What it tests
graphs · topological sort
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
