Days to Overtake Another Coder
Updated
Problem statement
Coder A solves dailyA problems each day, and coder B solves dailyB each day. For this exercise, assume that at day 0 A has solved 0 problems and B has solved gap problems.
Return the smallest whole number of elapsed days after which A has solved strictly more problems than B. Being tied is not enough. Return -1 if A can never overtake B. Daily counts are constant and nonnegative.
Function
daysToOvertake(dailyA: int, dailyB: int, gap: int) → intExamples
Example 1
dailyA = 3dailyB = 1gap = 4return = 3After 2 days both have solved 6 problems, so the tie is insufficient. After 3 days A has 9 and B has 7.
Example 2
dailyA = 2dailyB = 2gap = 1return = -1B starts ahead, and equal daily counts never reduce the gap.
Constraints
0 <= dailyA, dailyB <= 10000000 <= gap <= 1000000000
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Floor Square Roots for an ArrayWells Fargo · OAWells Fargo interview questions
- Arrange CoinsAlarm.com · OA
- Complete Rows of a Coin StaircaseExpedia · OAExpedia interview questions
- Perfect Squares Matching a PatternNielsen · OA
- Maximum Alloy Production Within BudgetMicrosoft · OAMicrosoft interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Count Lucky Numbers in a RangeTarget · OA
- Cyber Beacon DetectionRippling · OARippling interview questions
- Souvenir Shop PurchasesAmazon · OA