Two-Egg Dropping
Updated
Problem statement
A building has floors 1 through n. Some unknown floor f is the highest safe floor, where 0 <= f <= n. You have two identical eggs. An egg dropped from a floor above f breaks. An egg dropped from floor f or lower does not break, and you can drop it again. A broken egg cannot be used again.
You may choose each drop based on what happened in the earlier drops. Return the smallest number of drops that always lets you find f, even in the worst case.
Function
twoEggDrop(n: int) → intExamples
Example 1
n = 1return = 1A single drop from the only floor shows whether f is 0 or 1, so one drop is enough.
Example 2
n = 6return = 3Drop the first egg from floor 3, then 5, then 6, moving up only while it survives. If it breaks, use the second egg on the untested floors below it, one at a time from the lowest. Every case needs at most three drops.
Example 3
n = 50return = 10Nine drops can check at most 45 floors, which is too few for this building. Ten drops can check 55 floors, which is enough, so the answer is ten.
Constraints
1 <= n <= 1000.- One fixed floor
fdecides every drop, so a drop from the same floor always gives the same result.
More NVIDIA Onsite Interview questions
- Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
- Implement MallocONSITE INTERVIEW · Seen Sep 2026
- Implement PrintfONSITE INTERVIEW · Seen Sep 2026
- Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
- Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
- Ping Reply TrackingONSITE INTERVIEW · Seen Sep 2026
- Reverse A StringONSITE INTERVIEW · Seen Sep 2026
- Maximum Fish in a GridONSITE INTERVIEW · Seen Sep 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- First Register Overflow TickONSITE INTERVIEW · Seen May 2024
Similar questions at other companies
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Integer BreakAmazon · ONSITE INTERVIEW
- Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Count Divisible Power SumsGoodScore · ONSITE INTERVIEW
- Tile a Three-Row Board with DominoesJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Best Expected Result in Simplified BlackjackHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Split a Number into Non-Decreasing GroupsExpedia · OA · ONSITE INTERVIEWExpedia interview questions
- Fibonacci NumberMicrosoft · ONSITE INTERVIEWMicrosoft interview questions