Reported July 2026
Walmartgreedy

K-Capable Model Costs

Reported by candidates from Walmart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Walmart OA. Under 2s to a working solution.
Founder's read

Walmart reported this one in July 2026, and it looks easy until k starts growing. K-Capable Model Costs hands you models tagged 00, 01, 10 or 11, and you need the cheapest set for every k from 1 to n. The trap is the 11 model, which counts toward both features at once. A greedy that just grabs the cheapest items per feature will overpay or undercount. It's a sort-and-greedy problem with a sweep over how many dual models you take. If you blank mid-assessment, StealthCoder runs invisibly on screen as a safety net.

The problem

There are n machine learning models. Model i has cost cost[i] and a two-character string featureAvailability[i]:
"00": supports neither feature.
"01": supports Feature B only.
"10": supports Feature A only.
"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 "11" model counts toward both totals.
For every k from 1 to n, return the minimum total cost needed to choose a k-capable set. If no such set exists, return -1 for that k.
Return a long[] containing the answers for k = 1 through n.

Function
getMinimumModelCosts(cost: int[], featureAvailability: String[]) → long[]

Examples
Example 1
cost = [3,2,5,4]
featureAvailability = ["10","01","11","00"]
return = [5,10,-1,-1]
For k = 1, either the dual-feature model or the two single-feature models cost 5. For k = 2, the first three useful models cost 10. Larger values of k are impossible.
Example 2
cost = [8,1,2,6]
featureAvailability = ["11","10","01","11"]
return = [3,9,17,-1]
For k = 1, pair the models costing 1 and 2. For k = 2, also choose the dual-feature model costing 6. For k = 3, all four models are required. The value k = 4 is impossible.

Constraints
1 <= n <= 10^5
1 <= cost[i] <= 10^9
featureAvailability[i] is one of "00", "01", "10", or "11".

Reported by candidates. Source: FastPrep

Pattern and pitfall

Split the models into four lists by tag and sort each by cost. Build prefix sums for each list. For a given k, pick j dual (11) models, the j cheapest. Then you need k-j from the A-only list and k-j from the B-only list, again the cheapest. Cost is prefix11[j] + prefixA[k-j] + prefixB[k-j], valid only if the lists are long enough. Minimize over j. The edge case that breaks the naive version: taking all the cheap singles and ignoring that one dual model can replace two singles, or forgetting j can't exceed k. The 00 models are never useful, so ignore them. Naive looping over every k and j is O(n^2), which is too slow at 10^5. Use the fact that the optimal j changes monotonically, or sweep a pointer, and note that leftover cheap items can also fill extra slots. Use long for sums, since costs reach 10^9. If the sweep logic slips under pressure, StealthCoder is the hedge during the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill K-Capable Model Costs 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 StealthCoder

Related leaked OAs

⏵ The honest play

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 Costs FAQ

What's the trick in K-Capable Model Costs?+

Sort the 10, 01 and 11 groups by cost and build prefix sums. For each k, you choose how many dual models to take, then fill the rest of each feature with the cheapest singles. The 00 models are dead weight and get ignored.

Why does a simple greedy fail here?+

Because a 11 model covers both features for one price. Sometimes it beats two singles, sometimes not. Picking per feature independently misses that tradeoff, and you'll overpay or double count. You have to compare combinations of dual and single picks.

What's the brute force and why won't it pass?+

Looping over every k and every possible dual count j is O(n^2). With n up to 10^5 that's too slow. You need a pointer sweep or monotonic optimal j so the total work stays near O(n log n) after sorting.

Which edge cases should I test?+

Test when k exceeds available A or B capacity, so the answer is -1. Test lists with no dual models, only dual models, and all 00 models. Also check overflow, since sums of 10^5 costs at 10^9 need a long.

How do I prepare for this in 48 hours?+

Practice sort plus prefix sum problems where you choose from several categories under a count constraint. Write this one out once with four lists and the j sweep. Know your return type is long[] and that -1 marks impossible k values.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Walmart.

OA at Walmart?
Invisible during screen share
Get it