Eggs dropping puzzle | Set 2 | Function to return the minimum number of trials needed in the worst case with n eggs and k floors ; Fill all the entries in table using optimal substructure property ; Return the minimum number of moves ; Driver code
function eggDrop ( n , k ) { let dp = new Array ( ) ; for ( let i = 0 ; i < k + 1 ; i ++ ) { dp . push ( new Array ( n + 1 ) . fill ( 0 ) ) } let x = 0 ; while ( dp [ x ] [ n ] < k ) { x ++ ; for ( let i = 1 ; i <= n ; i ++ ) dp [ x ] [ i ] = dp [ x - 1 ] [ i - 1 ] + dp [ x - 1 ] [ i ] + 1 ; } return x ; } let n = 2 , k = 36 ; document . write ( eggDrop ( n , k ) ) ;