EasyMathBinary Search

Valid Perfect Square

LeetCode
2 approaches, code in all languages

Given a positive integer, decide whether it is a perfect square, meaning it equals some whole number multiplied by itself. Return true when such a whole number exists and false otherwise.

The catch is that built-in square-root helpers are not allowed, so you must determine the answer using arithmetic and a search of your own.

Example 1

Input: num = 16

Output: true

16 is 4 times 4, so it is a perfect square.

Example 2

Input: num = 14

Output: false

No whole number squared gives 14, so the answer is false.

Constraints

  • 1 ≤ num ≤ 2^31 - 1
  • You may not use any built-in square root function
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now