FastPrepParticipant Count from Coffee and Milk Shares

Participant Count from Coffee and Milk Shares

IMC Trading logoIMC Trading● EasyINTERNPHONE SCREEN
Learn

Problem statement

Coffee and milk are shared among an unknown positive integer number of participants. Every participant receives the same combined volume servingOunces, with different coffee-to-milk ratios. One participant receives exactly 1/coffeeDenominator of the entire coffee supply and 1/milkDenominator of the entire milk supply.

For this exercise, assume both total supplies are strictly positive, all of both supplies are distributed, and fluid is continuously divisible. Equal combined volumes do not require equal drink ratios.

For this exercise, assume the denominators are integers differing by exactly 2. This generalizes the reported denominators 4 and 6 while retaining a uniquely determined integer participant count. The reported participant receives 8 ounces; the positive serving volume is also an input.

Complete participantCount(coffeeDenominator, milkDenominator, servingOunces) and return the unique total number of participants. The answer is a count, rather than the combined supply volume.

Function

participantCount(coffeeDenominator: int, milkDenominator: int, servingOunces: int) → int

Examples

Example 1

coffeeDenominator = 4milkDenominator = 6servingOunces = 8return = 5

This is the reported numerical case under the stated assumptions. A total of 16 ounces of coffee and 24 ounces of milk gives five equal eight-ounce servings. The specified participant receives 16/4 + 24/6 = 8 ounces. One possible distribution of coffee/milk ounces is (4,4), (0.5,7.5), (1.5,6.5), (4.5,3.5) and (5.5,2.5); all five ratios are different.

Example 2

coffeeDenominator = 2milkDenominator = 4servingOunces = 3return = 3

This authored example admits 3 ounces of coffee and 6 ounces of milk. The specified participant receives 3/2 + 6/4 = 3 ounces. The combined nine ounces make three equal servings.

Example 3

coffeeDenominator = 8milkDenominator = 6servingOunces = 1return = 7

This authored example reverses the smaller denominator. Coffee and milk totals can be 4 and 3 ounces. The specified participant receives 4/8 + 3/6 = 1 ounce, and there are seven equal servings.

Constraints

  • For this exercise, assume 2 <= coffeeDenominator, milkDenominator <= 10^5.
  • abs(coffeeDenominator - milkDenominator) = 2.
  • For this exercise, assume 1 <= servingOunces <= 10^6.
  • Both entire supplies are positive and completely distributed in equal combined servings.
  • Fluid volumes need not be whole numbers of ounces.

More IMC Trading problems

See IMC Trading hiring insights
public int participantCount(int coffeeDenominator, int milkDenominator, int servingOunces) {
    // Write your solution here.
}
coffeeDenominator4
milkDenominator6
servingOunces8
expected5
Checking account…