forked from GFGSC-RTU/GFG-SDE-Sheet-Solution-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e7f1e6
commit 989f39a
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#problem link: https://practice.geeksforgeeks.org/problems/egg-dropping-puzzle-1587115620/1 | ||
|
||
INT_MAX = 32767 | ||
|
||
def eggDrop(n, k): | ||
eggFloor = [[0 for x in range(k + 1)] for x in range(n + 1)] | ||
|
||
for i in range(1, n + 1): | ||
eggFloor[i][1] = 1 | ||
eggFloor[i][0] = 0 | ||
|
||
|
||
for j in range(1, k + 1): | ||
eggFloor[1][j] = j | ||
|
||
for i in range(2, n + 1): | ||
for j in range(2, k + 1): | ||
eggFloor[i][j] = INT_MAX | ||
for x in range(1, j + 1): | ||
res = 1 + max(eggFloor[i-1][x-1], eggFloor[i][j-x]) | ||
if res < eggFloor[i][j]: | ||
eggFloor[i][j] = res | ||
|
||
return eggFloor[n][k] | ||
|
||
n = 2 | ||
k = 36 | ||
print("Minimum number of trials in worst case with" + str(n) + "eggs and " | ||
+ str(k) + " floors is " + str(eggDrop(n, k))) | ||
|