Optimal Offer for Hidden Product Quality
Updated
Problem statement
A seller has one item of unknown quality. The probability that its quality is outcome i is weights[i] / sum(weights). Its value to you is values[i], and the seller accepts an offer only when its integer price is at least thresholds[i].
For this exercise, assume you make one nonnegative integer offer before learning the quality. When the seller accepts, your profit is values[i] - price; otherwise it is zero. Return the offer price that maximizes expected profit. If several prices are best, return the smallest.
For this exercise, assume the finite arrays generalize the reported two-quality case. Outcomes with zero weight cannot occur. The arrays describe the same outcomes, and their order has no effect. The inputs must remain unchanged.
Complete optimalPurchaseOffer(values, thresholds, weights) and return an integer price.
Function
optimalPurchaseOffer(values: int[], thresholds: int[], weights: int[]) → intExamples
Example 1
values = [7000,10000]thresholds = [3000,7000]weights = [7,3]return = 3000An offer of 3000 buys only the 70% quality and has expected profit 0.7*(7000-3000)=2800. At 7000, expected profit is 900. Offers between acceptance thresholds only lower the profit.
Example 2
values = [2,1]thresholds = [5,3]weights = [1,1]return = 0Every accepted purchase loses money. Price zero makes no sale and yields expected profit zero, so it is optimal.
Example 3
values = [4,8]thresholds = [2,6]weights = [1,1]return = 2Price two earns weighted profit numerator two. Price six also earns two because it buys both qualities. Choose the smaller optimal price, two.
Example 4
values = [10]thresholds = [0]weights = [1]return = 0The seller accepts price zero. That gives profit ten; every higher price decreases it.
Constraints
- For this exercise, assume equal array lengths from
1through100. 0 <= values[i] <= 1000000,0 <= thresholds[i] <= 10000, and0 <= weights[i] <= 1000000.- The sum of weights is positive. Weights specify proportional probability mass, not monetary amounts.
- Weighted profit numerators fit signed 64-bit arithmetic under these bounds. No fees or extra payoffs are added.
More IMC Trading interview questions
- Pro-Rata Order BookONSITE INTERVIEW · Seen Sep 2026
- Matching Engine with Order CancellationONSITE INTERVIEW · Seen Jun 2026
- Newspaper Delivery GameONSITE INTERVIEW · Seen Oct 2023
- Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
- Grid Paths with Override PassesOA · Seen Oct 2026
- Weighted LFU CacheOA · Seen Sep 2026
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Rock JumpingOA · Seen Aug 2026
- Stack Batch RemovalOA · Seen Aug 2026
- Chain of CommandOA · Seen Aug 2026
Similar questions at other companies
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Pythagorean Triple with Array MultiplicityByteDance · ONSITE INTERVIEWByteDance interview questions
- Best Restart Cutoff for a Long-Tailed JobOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Build a Precision-Recall CurveMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Decision Tree Classifier from ScratchZillow · ONSITE INTERVIEWZillow interview questions
- Pick the K Nearest Grid Points to (0, 0)Capital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Allocate Mailboxes with Squared DistanceLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions