Skip to content
Discussion options

You must be logged in to vote

We can utilize a two-pointer approach. Here's how we can approach the problem:

Explanation:

  1. Constraints:

    • We're given a non-negative integer c.
    • We need to find two integers a and b such that a² + b² = c.
  2. Two-pointer Approach:

    • Start with two pointers: a initialized to 0, and b initialized to the square root of c.
    • The idea is to check the sum of the squares of a and b. If a² + b² equals c, return true.
    • If a² + b² is less than c, increment a to increase the sum.
    • If a² + b² is greater than c, decrement b to decrease the sum.
    • Continue this process until a is less than or equal to b.
    • If no such pair is found, return false.

Let's implement this solution in PHP: 633. Sum of Square Numbers

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Sep 9, 2024
Maintainer Author

@basharul-siddike
Comment options

Answer selected by mah-shamim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants