Expected Fishing Catch
Updated
Problem statement
A fishing trip can end in one of a fixed, finite list of outcomes. Outcome i brings in catches[i] fish. Its probability is weights[i] / sum(weights). The weights are integers that are zero or more, and their total is positive.
Return the expected number of fish caught on one trip. Two outcomes may have the same catch amount. Each of them still counts with its own weight. An outcome with zero weight adds nothing.
Complete expectedFishingCatch(catches, weights). It gets the outcome table as two arrays. Your answer is accepted when its absolute error is at most 1e-7 * max(1, abs(expected)). In other words, the tolerance is 1e-7, relative or absolute.
Function
expectedFishingCatch(catches: int[], weights: int[]) → doubleExamples
Example 1
catches = [0,2,5]weights = [1,2,1]return = 2.25Multiply each catch by its weight and add the results: 0+4+5=9. Divide by the total weight, 4, to get the answer 2.25.
Example 2
catches = [3]weights = [8]return = 3.0The only possible catch is three fish, so its probability is one and the expectation is three.
Example 3
catches = [0,0]weights = [1,1]return = 0.0Both outcomes catch zero fish, so the expected catch is zero.
Example 4
catches = [1,2]weights = [1,2]return = 1.6666666666666667The expected catch is (1+4)/3=5/3. Return it with its fractional part, not rounded to a whole fish.
Constraints
- Both arrays have the same length, from
1through100. 0 <= catches[i], weights[i] <= 1000000, and at least one weight is positive.- Return the expected catch as a
double. Do not round it to a whole fish. - The inputs are not modified.
More IMC Trading Phone Screen questions
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
- Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
- Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
- Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
- Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
- Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
- Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
- Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
- Poker Suit Expected ProfitPHONE SCREEN · Seen Sep 2023
Similar questions at other companies
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Circular Primes Below a LimitAmazon · PHONE SCREEN
- Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Streaming AverageXantium · PHONE SCREEN
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN