FastPrepNumbers With Exactly Two Square-Sum Representations
Problems/Numbers With Exactly Two Square-Sum Representations

Numbers With Exactly Two Square-Sum Representations

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand new-grad report from Google asks for every value below n that can be written in exactly two different ways as a sum of two non-negative squares, with the order of the two squares not mattering. The function returns the values in increasing order.

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

Interview reports that mention this question

  • Google New Grad R1, Two Square Sums: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] numbersWithExactlyTwoSquareSums(int n) {
        // Write your code here.
    }
}
Checking account…