Valid Perfect Square

EasyBinary Searchbinary search

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given a positive integer num, return true if num is the square of some integer, and false otherwise. Do not use a built-in square root (sqrt, ** 0.5, isqrt, etc.). Aim for O(log num) time.

Examples

Input: num = 16
Output: true
4 * 4 = 16.
Input: num = 14
Output: false
3 * 3 = 9 and 4 * 4 = 16, so no integer squares to 14.

Constraints

  • 1 <= num <= 2^31 - 1

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More binary search problems