Dice Outcomes That Make a Perfect Square
Updated
Problem statement
You roll two fair dice, each with faces numbered 1 to sides. An outcome is the ordered pair (first die, second die), so there are sides * sides equally likely outcomes. You can picture them as the cells of a sides by sides table.
If combine is "sum", combine the two faces by adding them. If it is "product", multiply them.
Return the number of outcomes whose combined value is a perfect square.
Function
countSquareOutcomes(sides: int, combine: String) → intExamples
Example 1
sides = 8combine = "product"return = 12The product of two faces is a perfect square for these 12 ordered outcomes: (1, 1), (2, 2), ..., (8, 8) (eight of them), plus (1, 4), (4, 1), (2, 8) and (8, 2).
Example 2
sides = 8combine = "sum"return = 12The sum ranges from 2 to 16, so it can be the square 4, 9 or 16. A sum of 4 comes from 3 outcomes, a sum of 9 from 8 outcomes ((1, 8) through (8, 1)), and a sum of 16 only from (8, 8). That is 3 + 8 + 1 = 12.
Example 3
sides = 4combine = "product"return = 6The products that are perfect squares come from (1, 1), (2, 2), (3, 3), (4, 4), (1, 4) and (4, 1), so the answer is 6.
Constraints
1 <= sides <= 105combineis either"sum"or"product".
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Get Triplet CountIBM · OAIBM interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 interview questions
- Counting Triplets Divisible by DAT&T · OAAT&T interview questions
- Find Number of Ways to Group ParcelsAmazon · OA
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Filter Paginated Medical RecordsNVIDIA · PHONE SCREENNVIDIA interview questions
Interview reports that mention this question
Jane Street interview experiences
- Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)