Sum of Square Numbers
MediumMathtwo pointers
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 neededProblem
Given a non-negative integer c, return true if there exist integers a >= 0 and b >= 0 with a*a + b*b == c, and false otherwise.
a and b may be equal, and either may be 0. Aim for O(sqrt(c)) time using integer arithmetic only, so large inputs have no floating-point error.
Examples
Input: c = 5
Output: true
1*1 + 2*2 = 5.
Input: c = 3
Output: false
The squares up to 3 are 0 and 1, and no two of them sum to 3.
Constraints
- 0 <= c <= 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.