Check if a number is perfect square without finding square root | Program to find if x is a perfect square . ; Check if mid is perfect square ; Mid is small -> go right to increase mid ; Mid is large -> to left to decrease mid ; Driver Code ; Function Call
function isPerfectSquare ( x ) { let left = 1 , right = x ; while ( left <= right ) { let mid = parseInt ( ( left + right ) / 2 ) ; if ( mid * mid == x ) { return true ; } if ( mid * mid < x ) { left = mid + 1 ; } else { right = mid - 1 ; } } return false ; } let x = 2500 ; if ( isPerfectSquare ( x ) ) document . write ( " " ) ; else document . write ( " " ) ;