FastPrepOptimal Offer for Hidden Product Quality

Optimal Offer for Hidden Product Quality

IMC Trading logoIMC Trading● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

A seller has one item whose hidden quality is outcome i with probability 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[]) → int

Examples

Example 1

values = [7000,10000]thresholds = [3000,7000]weights = [7,3]return = 3000

An 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 = 0

Every 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 = 2

Price 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 = 0

The seller accepts price zero. That gives profit ten; every higher price decreases it.

Constraints

  • For this exercise, assume equal array lengths from 1 through 100.
  • 0 <= values[i] <= 1000000, 0 <= thresholds[i] <= 10000, and 0 <= 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 problems

See IMC Trading hiring insights
public int optimalPurchaseOffer(int[] values, int[] thresholds, int[] weights) {
    // Write your solution here.
}
values[7000,10000]
thresholds[3000,7000]
weights[7,3]
expected3000
Checking account…