Maximum height when coins are arranged in a triangle | Returns the square root of n . Note that the function ; We are using n itself as initial approximation . This can definitely be improved ; e decides the accuracy level ; Method to find maximum height of arrangement of coins ; calculating portion inside the square root ; Driver Code
function squareRoot ( n ) { let x = n ; let y = 1 ; let e = 0.000001 ; while ( x - y > e ) { x = ( x + y ) / 2 ; y = n / x ; } return x ; } function findMaximumHeight ( N ) { let n = 1 + 8 * N ; let maxH = ( - 1 + squareRoot ( n ) ) / 2 ; return Math . round ( maxH ) ; } let N = 12 ; document . write ( findMaximumHeight ( N ) ) ;