Ctrl K

Two Squares Make It

Medium
You are given a non-negative integer n. Return True if there are integers a and b with a² + b² = n, and False otherwise. a and b may be equal, and either of them may be zero.
Example 1
n=34 → True

34 = 3² + 5².

Example 2
n=21 → False

The squares up to 21 are 0, 1, 4, 9 and 16, and no two of them add up to 21.

Example 3
n=49 → True

49 = 0² + 7²: zero is allowed too.

Constraints
  • 0 ≤ n ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair in a Sorted List MediumRoll an Array to the Right MediumTriples Under a Limit MediumSpot the Extra Copy MediumSorted Parabola Values Medium
loading Python…
Input
n=34
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 44 tests on the server, hidden ones included.