Sum of Square Numbers

Given a non-negative integer c, decide whether there are two integers a and b such that a^2 + b^2 = c. Return true if such integers exist, otherwise return false.

Example 1
Inputc = 5
Outputtrue
1 * 1 + 2 * 2 = 5, so integers a = 1 and b = 2 satisfy the equation.
Example 2
Inputc = 3
Outputfalse
There are no two integers whose squared sum equals 3.

Constraints

  • 0 <= c <= 2^31 - 1

Asked at 7 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate