> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Sum of Square Numbers Python Solution

> Tested Python solution for LeetCode 633 with 21 pytest cases. Generate a practice environment with lcpy.

LeetCode 633, [Medium](/catalog/medium). Topics: [Math](/catalog/topics/math), [Two Pointers](/catalog/topics/two-pointers), [Binary Search](/catalog/topics/binary-search). [View on LeetCode](https://leetcode.com/problems/sum-of-square-numbers/description/).

Generate this problem as a practice environment: tested reference solution, 21 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 633   # by problem number
lcpy gen -s sum_of_square_numbers   # by problem name
```

## Problem

Given a non-negative integer `c`, decide whether there're two integers `a` and `b` such that `a^2 + b^2 = c`.

### Examples

```
Input: c = 5
Output: true
Explanation: 1 * 1 + 2 * 2 = 5
```

```
Input: c = 3
Output: false
```

### Constraints

* 0 \<= c \<= 2^31 - 1

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_square_numbers/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sum_of_square_numbers/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from math import isqrt


class Solution:
    # Time: O(sqrt(c))
    # Space: O(1)
    def judge_square_sum(self, c: int) -> bool:
        left, right = 0, isqrt(c)
        while left <= right:
            total = left * left + right * right
            if total == c:
                return True
            if total < c:
                left += 1
            else:
                right -= 1
        return False
```

## Complexity

| Time | Space |
| - | - |
| O(sqrt(c)) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.