Largest number in an array that is not a perfect cube | Function to check if a number is perfect cube number or not ; takes the sqrt of the number ; checks if it is a perfect cube number ; Function to find the largest non perfect cube number in the array ; stores the maximum of all perfect cube numbers ; Traverse all elements in the array ; store the maximum if current element is a non perfect cube ; Driver Code
function checkPerfectcube ( n ) { let d = Math . cbrt ( n ) ; if ( d * d * d == n ) return true ; return false ; } function largestNonPerfectcubeNumber ( a , n ) { let maxi = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! checkPerfectcube ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } let a = [ 16 , 64 , 25 , 2 , 3 , 10 ] ; let n = a . length ; document . write ( largestNonPerfectcubeNumber ( a , n ) ) ;