Painted Cube: Count and Roll
Updated
Problem statement
A large n x n x n cube is built from n3 unit cubes. The six outside faces of the large cube are painted, and then it is taken apart. A face of a unit cube is painted exactly when it was on the outside of the large cube.
Return an array [count, num, den] where:
countis the number of unit cubes with at most one painted face.num / denis the probability that you can see paint after this experiment: pick one unit cube uniformly at random and roll it like a fair die. When it stops, the face on the table is hidden and the other five faces are visible. Write the probability as a fraction in lowest terms.
Function
paintedCube(n: int) → long[]Examples
Example 1
n = 3return = [7,25,27]The cube in the very middle has no paint and the 6 cubes in the middle of the big faces have one painted face, so 7 cubes have at most one. The other 20 cubes (12 on the edges, 8 corners) have at least two painted faces and only one face is hidden, so they always show paint. A face-middle cube hides its paint only when it lands on that face, a chance of 1/6. The chance of seeing no paint is (1 + 6 * 1/6) / 27 = 2/27, so the chance of seeing paint is 25/27.
Example 2
n = 1return = [0,1,1]The only cube is painted on all six faces. No cube has at most one painted face, and paint always shows, so the probability is 1/1.
Example 3
n = 4return = [32,13,16]The inside is a 2 x 2 x 2 block of 8 unpainted cubes, and each big face has a 2 x 2 middle, giving 24 cubes with one painted face. That is 32 cubes. The chance of seeing no paint is (8 + 24 / 6) / 64 = 12/64 = 3/16, so the answer is 13/16.
Example 4
n = 5return = [81,89,125]27 inside cubes and 6 * 9 = 54 face-middle cubes give 81. The chance of seeing no paint is (27 + 54 / 6) / 125 = 36/125, so the answer is 89/125.
Example 5
n = 10return = [896,53,125]8^3 = 512 inside cubes and 6 * 64 = 384 face-middle cubes give 896. The chance of seeing no paint is (512 + 64) / 1000 = 72/125, so the answer is 53/125.
Constraints
1 <= n <= 105
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
- Random Points Inside One ArcSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Range of a Third CorrelationTower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Expected Fake-Name CollisionsMercor · PHONE SCREENMercor interview questions
- Union Area of Two RectanglesDocuSign · PHONE SCREENDocuSign interview questions
- Count Routes Through a City GridIMC Trading · PHONE SCREENIMC Trading interview questions
- Intersection of Two RectanglesFigma · PHONE SCREENFigma interview questions
- Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
- Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREENOpenAI interview questions