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
November 29, 20260
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
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
- 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 ProblemsSample Answer
Requirements
- Input:
n <= 15,deps[a, b](1-indexed features), andk. - Each train ships up to
kfeatures 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...