Zepruv › Coding problems

Valid Perfect Square

Easy · Math, Binary Search

Given a positive integer num, return true if num is a perfect square or false otherwise.
A perfect square is an integer that is the square of an integer. In other words, it is the product of some integer with itself.
You must not use any built-in library function, such as sqrt.

Example 1

Input: num = 16
Output: true

We return true because 4 * 4 = 16 and 4 is an integer.

Example 2

Input: num = 14
Output: false

We return false because 3.742 * 3.742 = 14 and 3.742 is not an integer.

Constraints

Starter code (python)

class Solution(object):
    def isPerfectSquare(self, num):
        """
        :type num: int
        :rtype: bool
        """
        

Related problems

Previous: Max Sum of Rectangle No Larger Than K · Next: Largest Divisible Subset · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.