Number of times the largest Perfect Cube can be subtracted from N | Function to return the count of steps ; Variable to store the count of steps ; Iterate while N > 0 ; Get the largest perfect cube and subtract it from N ; Increment steps ; Return the required count ; Driver code
function countSteps ( n ) { let steps = 0 ; while ( n ) { let largest = Math . floor ( Math . cbrt ( n ) ) ; n -= ( largest * largest * largest ) ; steps ++ ; } return steps ; } let n = 150 ; document . write ( countSteps ( n ) ) ;