Skip to content

Commit

Permalink
Create EggDroppingProblem.py
Browse files Browse the repository at this point in the history
  • Loading branch information
srishti666 authored Oct 9, 2022
1 parent 1e7f1e6 commit 989f39a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Solutions/EggDroppingProblem.py
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)))

0 comments on commit 989f39a

Please sign in to comment.