Grandmother's Age From Her Grandchildren
Updated
Problem statement
A grandmother's age is a two-digit number. Her two grandchildren are as old as the two digits of that number: one is as old as the tens digit and the other as old as the ones digit. For example, if she were 73, the grandchildren would be 7 and 3. A grandchild may be 0 years old.
The grandmother's age and the ages of the two grandchildren add up to total. Return the grandmother's age, or -1 if no two-digit age works. At most one age can work.
Function
grandmotherAge(total: int) → intExamples
Example 1
total = 100return = 86Write her age as 10a + b, so the grandchildren are a and b years old and the total is 11a + 2b = 100. Since 2b and 100 are even, a must be even. With a = 8 we get 2b = 12, so b = 6. Check: 86 + 8 + 6 = 100. A smaller even a would need b above 9.
Example 2
total = 50return = 4343 + 4 + 3 = 50. Here 11a + 2b = 50 gives a = 4 and b = 3.
Example 3
total = 101return = 9191 + 9 + 1 = 101. The total is odd, so a must be odd, and a = 9 leaves 2b = 2.
Example 4
total = 11return = 1010 + 1 + 0 = 11. The younger grandchild is a baby under one year old.
Example 5
total = 12return = -1We need 11a + 2b = 12 with a at least 1. The total is even, so a is even and at least 2, but then 11a = 22 is already more than 12. No age works.
Constraints
1 <= total <= 200
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- 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
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe 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
- Employee Count Median, Mean and ModeClay · PHONE SCREEN