K-Capable Model Selection
Reported by candidates from Walmart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that sinks most first attempts at Walmart's K-Capable Model Selection, reported in June 2026, is the "11" model. It counts toward both features, so a naive greedy that treats A and B separately double-spends or double-counts. You need the cheapest set of models where at least k support Feature A and at least k support Feature B, for every k from 1 to n. It's a sorting plus greedy problem with prefix sums on top. If you blank during the live OA, StealthCoder runs invisibly as a safety net, but the logic below is short enough to own.
The problem
You are given n machine learning models. For each model: cost[i] is the cost of the ith model. featureAvailability[i] is a binary string of length 2 describing which features the model supports. The availability string has the following meaning: "00": supports neither Feature A nor Feature B. "01": supports only Feature B. "10": supports only Feature A. "11": supports both Feature A and Feature B. A selected set of models is k-capable if at least k selected models support Feature A and at least k selected models support Feature B. A model with availability "11" contributes to both counts. For every integer k from 1 to n, determine the minimum total cost required to select a k-capable set of models. If it is impossible for a value of k, return -1 for that value. Function minimumKCapableCosts(cost: int[], featureAvailability: String[]) → long[] Complete the function minimumKCapableCosts. int[] cost: the model costs. String[] featureAvailability: the feature availability strings. Returns long[]: an array of length n, where the k - 1 index stores the minimum total cost for k. Examples Example 1 cost = [3, 2, 5] featureAvailability = ["10", "01", "11"] return = [5, 10, -1] For k = 1, selecting the third model costs 5 and covers both features. For k = 2, all three models are required, for total cost 10. For k = 3, there are not enough models supporting either feature, so the answer is -1. Constraints cost.length == featureAvailability.length Each featureAvailability[i] is one of "00", "01", "10", or "11".
Reported by candidates. Source: FastPrep
Pattern and pitfall
Split models into four buckets by availability string and sort each by cost. Build prefix sums for each bucket. For a given k, pick j models from the "11" bucket. Then you need max(0, k-j) from the "10" bucket and max(0, k-j) from the "01" bucket. Cost is the sum of those three prefix lookups. Try every valid j and take the minimum. If any bucket lacks enough models, that j is invalid. If no j works, return -1. The pitfall is assuming you should always take the cheapest "11" first, or never take extras. A cheap "00" model never helps, so ignore that bucket entirely. Also remember a chosen "11" model could be cheaper than a "10" plus a "01" pair, which is why you iterate j rather than guess. Use long for sums. Complexity is O(n^2) with the simple loop over k and j, which is fine at modest n. If n is large, the optimal j moves monotonically and you can tighten it. StealthCoder is your hedge if the loop bounds slip under pressure.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill K-Capable Model Selection cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Walmart's OA.
Walmart reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
K-Capable Model Selection FAQ
What's the trick in K-Capable Model Selection?+
Bucket models by availability string, sort each bucket, and build prefix sums. For each k, iterate how many "11" models you take, then fill the remaining A and B needs from the "10" and "01" buckets. Take the minimum over all valid splits.
Why can't I just greedily pick the cheapest models for A and B?+
Because "11" models serve both features at once. Picking cheapest per feature independently can overpay or double-count. Sometimes one pricey "11" beats a "10" plus a "01". You have to compare across different counts of "11" models.
When do I return -1 for a k?+
When no choice of j works. For a given j, you need j at most the size of the "11" bucket, and k-j at most the size of both the "10" and "01" buckets. If every j fails those checks, that k returns -1, like k=3 in the example.
Do "00" models matter?+
No. They support neither feature, so they only add cost. Selecting them never helps a k-capable set. Drop them early and don't let them leak into your prefix sums.
How do I prepare for this in 48 hours?+
Practice bucketing plus prefix sums on a similar problem, then hand-trace the example: cost [3,2,5] gives [5,10,-1]. Write the loop over k and j once from scratch. Use long for totals, since sums can overflow int.