Challenge: Egg Dropping Problem
Let's solve the famous egg dropping problem!
We'll cover the following
Problem Statement
Given a tall skyscraper and a few eggs, write a function to figure out how many tries it would take to figure out which floor of the skyscraper that the eggs can be safely dropped from without breaking. Here are some rules,
- An egg that survives a fall can be used again. A broken egg must be discarded.
- The effect of a fall is the same for all eggs.
- If an egg breaks when dropped, then it would break if dropped from a higher floor.
- If an egg survives a fall then it would survive a shorter fall.
Input
Two integers that represent the number of stories of the skyscraper and number of eggs respectively.
Output
The least number of egg-droppings to figure out the critical floor.
Sample Input
int eggs = 6;
int floors = 15;
Sample Output
4
Coding Exercise
Take a close look and design a step-by-step algorithm before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the hint and solution provided in the code tab. Good Luck!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.