The interview problem
Select at most two exercises for an interview preparation session. Each exercise covers a known subset of skills. Maximize the number of distinct skills covered. Explain a greedy algorithm, prove a performance guarantee under precise assumptions, and show why that guarantee can fail when exercises have prerequisites or unequal durations.
Original fundamentals practice, not a reported company question. Examples and calculations are original. Primary technical reference retrieved September 27, 2026; interview date not applicable.
1. Define what the objective measures
Let V be a finite catalog of exercises. Each exercise e covers a fixed set C(e) of skills. Give each skill j a fixed nonnegative weight w(j), and define f(S) as the total weight of skills covered by at least one exercise in S. An already covered skill contributes no additional value when another exercise repeats it.
f(S) = sum of w(j) over j in the union of C(e), e in S maximize f(S), subject to |S| ≤ k
Assume equal exercise costs, a cardinality budget k between 1 and |V|, reliable skill labels and no ordering or prerequisite effects. The empty set has value zero. A budget of zero is a separate trivial case.
This is a coverage objective, not a direct measure of learning. Repetition may improve retention, prerequisites may make advanced material useful, and fatigue may reduce performance. Those effects require a different model. An approximation guarantee cannot validate the business objective itself.
2. Use marginal gains instead of standalone scores
Define the marginal gain of an unselected exercise e given selected exercises S:
Δ(e | S) = f(S ∪ {e}) − f(S)Coverage is monotone: adding an exercise cannot reduce the value because all skill weights are nonnegative. It also exhibits diminishing returns. If S is a subset of T, then fewer skills remain uncovered under T, so adding the same exercise cannot contribute more:
S ⊆ T, e ∉ T ⇒ Δ(e | S) ≥ Δ(e | T)
This inequality defines submodularity. Monotonicity and submodularity are separate properties. A function can have diminishing returns yet decrease when an item is added, and a monotone function can exhibit complementarity rather than diminishing returns.
Greedy selection starts with the empty set and repeatedly chooses an unselected exercise with the largest current marginal gain. Recompute gains after every selection. Use a deterministic tie-break to make the result reproducible. With a monotone submodular objective, stop early if every remaining marginal is zero: further additions cannot improve this fixed objective.
3. Work through a case where greedy is imperfect
There are six equally weighted skills and three candidate exercises. Select at most two.
| Exercise | Skills covered | Standalone value | Marginal after A |
|---|---|---|---|
| A | 1, 2, 3, 4 | 4 | Already selected |
| B | 1, 2, 5 | 3 | 1 |
| C | 3, 4, 6 | 3 | 1 |
Greedy selects A first. Either B or C then adds one new skill, producing value 5. But B and C together cover all six skills.
f({A,B}) = 5
f({A,C}) = 5
f({B,C}) = 6
greedy / optimum = 5/6 ≈ 83.33%Enumerating all pairs proves optimality for this small example; the singleton values are smaller. Greedy is not exact even when every required assumption holds.
Now imagine a second exercise A′ covering exactly the same four skills as A. A standalone-score ranking might choose A and A′, covering only four skills. Marginal selection recognizes that A′ adds zero after A. Updating gains is the central operation, not a cosmetic reranking step.
4. Derive the cardinality guarantee
Assume f is normalized, nonnegative, monotone and submodular, and each greedy step uses the true largest marginal gain. Let O be an optimal feasible set, and let Sᵢ be the set after i greedy choices. Write OPT = f(O).
Adding all elements of O to Sᵢ gives value at least OPT by monotonicity. Add those elements one at a time. Submodularity says each gain in that sequence is no larger than its marginal measured at Sᵢ. There are at most k elements in O, so:
OPT − f(Sᵢ) ≤ f(Sᵢ ∪ O) − f(Sᵢ) ≤ sum over e in O \ Sᵢ of Δ(e | Sᵢ) ≤ k × max remaining Δ(e | Sᵢ)
Greedy takes the largest remaining marginal. Therefore it closes at least one kth of the current gap:
OPT − f(Sᵢ₊₁) ≤ (1 − 1/k)[OPT − f(Sᵢ)]
Starting from f(S₀) = 0 and applying this recurrence k times gives:
f(Sₖ) ≥ [1 − (1 − 1/k)ᵏ] OPT
≥ (1 − 1/e) OPT
≈ 0.6321 OPTFor k = 2, the finite bound is 1 − (1/2)² = 3/4. Our example achieves 5/6, above that bound. For k = 1, greedy is exact. If every marginal becomes zero before k choices, the same gap inequality implies that the remaining gap is zero under these assumptions.
The bound is worst-case and relative to the best set within the supplied catalog and the same cardinality limit. It is neither a prediction that every run achieves exactly 63.21% nor a promise about learner outcomes. Approximate, noisy or stale marginal estimates require an additional error argument.
5. Break the guarantee with prerequisites
Suppose exercises X and Y are valuable only together, while Z gives a small standalone benefit. Define an original objective on these three items:
f(S) = 100 × indicator that both X and Y are in S
+ 1 × indicator that Z is in S
budget k = 2The function is normalized, nonnegative and monotone. But it is not submodular: adding Y to the empty set gives zero, whereas adding Y after X gives 100. Its marginal gain increases.
Greedy must start with Z because its gain is 1, compared with zero for X and Y. It can then select only one member of the valuable pair. Its final value is 1, while selecting X and Y gives 100. Continuing through zero-gain steps does not help within this budget.
Replace 100 with any large number M. The ratio becomes 1/M, so monotonicity alone cannot provide a positive constant guarantee for this algorithm. Treating prerequisites as ordinary overlapping skill coverage conceals the failure.
One modeling option is to create prerequisite bundles. That changes candidate costs and may create overlap between bundles, so it does not automatically restore the cardinality theorem. Another is to use a search or optimization method that explicitly models the complementary interactions. State the revised problem before choosing its solver.
6. Unequal durations change the problem
If exercises take different amounts of time, the constraint becomes a total-duration budget. Simply choosing the largest gain per minute does not inherit the preceding proof.
Consider a budget of 1, with two independent items. L costs 1 and has value 1. S costs ε and has value 2ε, where 0 < ε < 1/2. Their values add, making this objective modular and therefore submodular.
density(L) = 1 / 1 = 1 density(S) = 2ε / ε = 2 density greedy chooses S first remaining budget = 1 − ε, so L no longer fits greedy value = 2ε optimal value = 1
As ε approaches zero, the ratio approaches zero. With ε = 0.01, greedy obtains 0.02 against an optimum of 1. Comparing against the best feasible singleton would repair this particular example, but that observation is not a proof of the cardinality factor under a general cost constraint.
Use an algorithm and approximation theorem for the actual feasible family. A time budget, maximum counts per category and minimum coverage quotas are different constraints. The step that bounds the gap by k times a freely available marginal cannot simply be reused when the best marginal item is infeasible.
7. Build a selector with an auditable objective
versioned candidates + fixed skill weights
↓
coverage oracle and feasibility contract
↓
select maximum current marginal
↓
update covered skills and remaining budget
↓
selected exercises + marginal-gain auditFor pure cardinality selection, a straightforward implementation scans all remaining candidates at each of k steps: O(nk) marginal evaluations. The runtime of an evaluation depends on the skill representation. Sparse skill lists can sum weights only for uncovered skills; unweighted bitsets can use union and population-count operations. O(nk) evaluations is not necessarily O(nk) total CPU work.
Record candidate identifiers, selected order, skill-map version, weights, each accepted marginal and tie-break decisions. The order here records algorithm execution; the coverage objective itself does not model presentation order. A learning interface may need a separate sequencing policy.
On small catalogs, compare with exhaustive enumeration to detect implementation errors and quantify the observed gap. For large catalogs, compare against simple baselines and inspect sensitivity to skill labels and weights. Verify that each selected item is feasible and the reported marginal gains sum to the final value because f starts at zero.
8. Accelerate safely with lazy evaluation
For a fixed submodular objective, an old marginal evaluated at a smaller selected set is an upper bound on its current value. A priority queue can exploit that property. Initialize it with singleton gains. Pop the candidate with the largest bound, recompute its current marginal, and accept it only when that refreshed value is at least every other remaining bound. Otherwise update its bound and continue.
This produces an exact maximum-marginal choice at each step, with a consistent tie policy. It may avoid many oracle evaluations when gains change little, but worst-case savings are not guaranteed.
The upper-bound argument fails if skill weights change during a run, coverage labels are revised, the objective has complements or estimates are noisy without valid confidence bounds. Freeze the objective snapshot or invalidate the cached bounds. A priority queue does not make stale estimates safe merely because it is faster.
Failure analysis and follow-ups
- Negative skill weights: Adding an exercise can lower value. Recheck monotonicity before invoking the guarantee or filling every slot.
- Misleading coverage labels: A mathematically good set may teach little if exercises only mention skills superficially. Audit labels and evaluate learning outcomes separately.
- Missing candidates: The guarantee compares with the optimum in the supplied catalog. Retrieval omissions can still exclude the most useful exercises.
- Noisy gains: A sampled estimate can reverse the largest-marginal decision. Quantify estimation error; exact-greedy theory is not a certificate for arbitrary noise.
- Category requirements: A rule such as “at least one ML and one systems exercise” changes feasibility. A greedy first choice can leave no feasible completion.
- Follow-up—weighted skills: Nonnegative fixed weights preserve the coverage argument; derive gains as the sum of newly covered weights.
- Follow-up—fatigue or order: A set function may no longer represent the decision. Explain the sequence-dependent objective rather than assuming the same theorem.
Self-review rubric
A strong answer defines marginal gain, explains coverage submodularity and states normalization, monotonicity, exact marginal selection and a cardinality constraint before quoting a bound. It computes the three pair values and derives the gap contraction. An excellent answer supplies both a complementary-item counterexample and an unequal-cost counterexample, explains the lazy upper-bound invariant and separates mathematical approximation from validity of the learning objective.
Sources and attribution
- Andreas Krause and Daniel Golovin, Submodular Function Maximization — author-hosted survey; definitions, coverage functions, Theorem 1.5, lazy evaluation and budgeted maximization. Exact publication date was not established from the retrieved copy. The survey attributes the classical cardinality theorem to Nemhauser and colleagues, 1978.
Retrieved September 27, 2026. The exercise catalog, prerequisite construction, unequal-duration example and worked calculations are original practice. No candidate report or company interview attribution is claimed.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.