Fewest Release Trains When Each Train Ships at Most K Features

Last updated: November 29, 2026

Quick Overview

There are n features (n at most 15) with dependencies [a, b] meaning a must ship in an earlier release train than b. Each train can ship at most k features. Return the minimum number of trains needed to ship everything.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


There are n features (n at most 15) with dependencies [a, b] meaning a must ship in an earlier release train than b. Each train can ship at most k features. Return the minimum number of trains needed to ship everything.

A hard Meta onsite question built on release trains for the mobile apps, where QA capacity caps how many features a train can carry. The interviewer is checking that you recognize the greedy layering from the unlimited version is wrong here, and that you fall back to a bitmask DP over completed sets with submask enumeration.

What the Interviewer Expects
  • Show why greedy (pick any k available) can be suboptimal
  • Define dp over bitmasks of shipped features
  • Compute the available set for each mask via prerequisite masks
  • Enumerate submasks of size k when more than k are available
  • State O(3^n) time and justify it for n up to 15
Key Topics to Cover
bitmask DP
submask enumeration
topological constraints
scheduling
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
  • Give a concrete example where a greedy choice loses a train.
  • How would you add a heuristic that prefers features with the longest remaining chain?
  • How does the approach change if n is 100?
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: n <= 15, deps [a, b] (1-indexed features), and k.
  • Each train ships up to k features whose prerequisites all shipped in earlier trains.
  • Output: minimum number of trains. Input is...
High-Level Design

Greedy fails. With k = 2, if features 1 and 2 are free and 3 is free but heads a long chain, shipping 1 and 2 first delays the chain by a train. Choosing which k to ship matters, and with `n <= 15...


Submit Your Answer
Markdown supported