Challenge: Egg Dropping Problem

Solve the famous egg dropping problem.

Problem statement

Given a tall skyscraper and a few eggs, write a function to figure out how many tries it would take to find which floor of the skyscraper can the eggs be safely dropped 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 the number of eggs, respectively.

Output

The least number of egg drops to figure out the critical floor.

Sample input

eggs = 6;
floors = 15;

Sample output

result = 4;

Coding Challenge

First, take a close look at this problem and design a step-by-step algorithm before jumping 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 solution provided in the solution section. Good luck!

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.