Smallest Lexicographic Install Order for Optional Windows Features

Last updated: November 29, 2026

Quick Overview

Given Windows optional feature names and prerequisite pairs (a, b) meaning a must be installed before b, return the install order that respects all prerequisites and is lexicographically smallest, or an empty list if no valid order exists.

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

0

0

0 solved


Given Windows optional feature names and prerequisite pairs (a, b) meaning a must be installed before b, return the install order that respects all prerequisites and is lexicographically smallest, or an empty list if no valid order exists.

A topological sort variant in the style of Microsoft screens, framed around the Turn Windows features on or off installer. Any valid order is not enough: the deterministic smallest order makes logs reproducible, so the interviewer checks you replace the queue with a min-heap and reason about why that is correct.

What the Interviewer Expects
  • Use Kahn's algorithm with a min-heap instead of a FIFO queue
  • Explain why greedily taking the smallest ready name yields the smallest order
  • Detect cycles by counting output length
  • Include features with no edges
  • State O((V + E) log V)
Key Topics to Cover
topological sort
heaps
lexicographic order
determinism
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 produce the lexicographically largest order?
  • How would you count the number of valid install orders for small inputs?
  • What if some features are already installed and can be skipped?
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

Input: list features of unique names and prereqs, a list of (a, b). Output: the lexicographically smallest valid ordering as a list, comparing element by element, or [] when there is a cycle....

High-Level Design

Kahn's algorithm picks any ready node. To make the output lexicographically smallest, always pick the smallest ready name, using a min-heap of ready features. The greedy is correct because the first p...


Submit Your Answer
Markdown supported