Numbers With Exactly Two Square-Sum Representations
Updated
Problem statement
Given an integer n, return every integer s with 0 <= s < n that can be written as a^2 + b^2 in exactly two distinct unordered ways.
Both a and b must be nonnegative integers. Treat (a, b) and (b, a) as the same representation, so each pair is counted only with a <= b.
Return qualifying values in increasing order.
Function
numbersWithExactlyTwoSquareSums(n: int) → int[]Examples
Example 1
n = 26return = [25]25 = 0^2 + 5^2 = 3^2 + 4^2.
Example 2
n = 51return = [25,50]50 = 1^2 + 7^2 = 5^2 + 5^2, and 25 also has exactly two representations.
Example 3
n = 10return = []No value below ten has exactly two distinct unordered representations.
Constraints
1 <= n < 2^31 - 1.- The returned array may be large; its size contributes to the output cost.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Find Accounts with Negative Converted BalancesStripe · PHONE SCREENStripe interview questions
- Implement k-Nearest NeighborsApple · PHONE SCREENApple interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Median of Parsed Integer StringsRippling · PHONE SCREENRippling interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- House ValuationIMC Trading · OAIMC Trading interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions