Order Skill Assessments by Prerequisites in Lexicographic Order
Last updated: November 29, 2026
Quick Overview
Given a list of skill assessments and prerequisite pairs (a, b) meaning a must be passed before b, return the lexicographically smallest valid order to take all assessments, or an empty list if the prerequisites contain a cycle.
0
0
0 solved
Given a list of skill assessments and prerequisite pairs (a, b) meaning a must be passed before b, return the lexicographically smallest valid order to take all assessments, or an empty list if the prerequisites contain a cycle.
LinkedIn Learning and Skill Assessments gate advanced topics behind basics. The question checks topological sorting with Kahn's algorithm, cycle detection, and whether you know to swap the queue for a heap to get a deterministic smallest order.
What the Interviewer Expects
- Builds indegree counts and an adjacency list
- Uses Kahn's algorithm and detects cycles when output is short
- Uses a min-heap to get the lexicographically smallest order
- Includes assessments with no edges
- States O((V + E) log V) complexity
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you report which assessments form the cycle?
- What if a member has already passed some assessments?
- How do you compute the minimum number of semesters if several can be taken in parallel?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: skills (list of names) and prereqs as (before, after) pairs. Any order respecting all pairs is valid; we want the smallest by string comparison at each step. Pairs may mention names not ...
High-Level Design
Kahn's algorithm repeatedly removes a node with indegree 0. Choosing the smallest available node at every step via a min-heap yields the lexicographically smallest topological order, because the first...