FastPrepDice Outcomes That Make a Perfect Square
Problems/Dice Outcomes That Make a Perfect Square

Dice Outcomes That Make a Perfect Square

Jane Street logoJane Street● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two Jane Street trading desk operations new grad reports from the UK, both about phone rounds held in late 2020 and early 2021. One asked, for two fair eight-sided dice, how many combinations give a product that is a perfect square. The other asked how many entries in an 8 by 8 table of dice-roll sums are perfect squares, without naming the dice.

Our function takes the number of faces and whether to add or multiply the two faces, and counts ordered outcomes, one per cell of the table. Counting ordered outcomes, other die sizes, the limits and the third example are ours.

Our version is about 85% the same as the reported question.

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) → int

Examples

Example 1

sides = 8combine = "product"return = 12

The 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 = 12

The 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 = 6

The 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 <= 105
  • combine is 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 TDOE New Grad Interview Questions: 11 Experiences

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)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public int countSquareOutcomes(int sides, String combine) {
      // Write your code here.
    }
}
Checking account…