Challenge: Egg Dropping Problem

Let's 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 figure out which floor of the skyscraper the eggs can be dropped from without breaking. Here are some rules:

  1. An egg that survives a fall can be used again but a broken egg must be discarded.
  2. The effect of a fall is the same for all eggs.
  3. If an egg breaks when dropped from a certain floor, it would also break if dropped from a higher floor.
  4. If an egg survives a fall from a certain floor, it would also survive a shorter fall.

Input

The inputs are two integers that represent the number of stories of the skyscraper and number of eggs respectively.

Output

The output is the least number of egg-droppings to figure out the critical floor.

Sample input

int eggs = 6;
int floors = 15;

Sample output

4

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