Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4408 |

@sanjay05 | 3762 |

@mantu_singh | 3666 |

@gfgaccount | 3605 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 953 |

@kanewilliamson123 | 894 |

@pradeeppatidar1999 | 868 |

@akhileshkumar562002 | 862 |

@wallflowe101 | 826 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@nikhilkushwah280 | 796 |

Complete Leaderboard |

You are given **N** identical eggs and you have access to a **K**-floored building from **1** to **K**.

There exists a floor **f** where **0** <= **f** <= **K **such that any egg dropped at a floor higher than **f** will break, and any egg dropped **at or below **floor **f **will **not break**. There are few rules given below.

- 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 the egg doesn't break at a certain floor, it will not break at any floor below.
- If the eggs breaks at a certain floor, it will break at any floor above.

Return the minimum number of moves that you need to determine with certainty what the value of **f** is.

For more description on this problem see wiki page

**Example 1:**

**Input:
N **= 1**, K **= 2
**Output: **2
**Explanation:
**1. Drop the egg from floor 1. If it
breaks, we know that f = 0.
2. Otherwise, drop the egg from floor 2.
If it breaks, we know that f = 1.
3. If it does not break, then we know f = 2.
4. Hence, we need at minimum 2 moves to
determine with certainty what the value of f is.

**Example 2:**

Input:N = 2, K = 10Output:4

**Your Task:**

Complete the function **eggDrop()** which takes two positive integer N and K as input parameters and returns the minimum number of attempts you need in order to find the critical floor.

**Expected Time Complexity** : O(N*K)

**Expected Auxiliary Space**: O(N*K)

**Constraints:**

1<=N<=200

1<=K<=200

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Egg Dropping Puzzle

...