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.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
topological sort
Kahn's algorithm
min-heap
cycle detection
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported