FastPrepChickens and Eggs

Chickens and Eggs

Jane Street logoJane Street● EasyFULLTIMEPHONE SCREEN

Updated

Problem statement

baseBirds chickens lay baseEggs eggs in baseDays days. Every chicken lays at the same steady rate, and the numbers may be fractions, as in the classic puzzle.

Return how many eggs birds chickens lay in days days. The answer may be a fraction too. Answers within 1e-6 of the exact value (relative error for values larger than 1) are accepted.

Function

eggs(baseBirds: double, baseEggs: double, baseDays: double, birds: double, days: double) → double

Examples

Example 1

baseBirds = 1.5baseEggs = 1.5baseDays = 1.5birds = 9days = 9return = 54.0

If 1.5 chickens lay 1.5 eggs in 1.5 days, then 1 chicken lays 1 egg in 1.5 days, so a chicken lays 2/3 of an egg per day. Nine chickens over nine days give 81 * 2/3 = 54 eggs.

Example 2

baseBirds = 1baseEggs = 2baseDays = 1birds = 5days = 7return = 70.0

One chicken lays 2 eggs per day, so 5 chickens lay 10 eggs per day, and 70 eggs in 7 days.

Example 3

baseBirds = 3baseEggs = 2baseDays = 4birds = 6days = 10return = 10.0

Three chickens over four days give 12 chicken-days and 2 eggs, so one chicken-day gives 1/6 of an egg. Six chickens over ten days give 60 chicken-days, so 10 eggs.

Constraints

  • 0.1 <= baseBirds, baseEggs, baseDays, birds, days <= 1000
  • Every input has at most two digits after the decimal point.

More Jane Street Phone Screen questions

Similar questions at other companies

Interview reports that mention this question

Jane Street interview experiences

All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public double eggs(double baseBirds, double baseEggs, double baseDays, double birds, double days) {
      // Write your code here.
    }
}
Checking account…