Digit Orders Divisible by 15
Updated
Problem statement
You are given a list of decimal digits digits. Write a number by placing all of the digits in some order, using each one exactly once. The number may not start with 0.
Return how many different numbers you can write this way that are divisible by 15. Orders that give the same number, such as swapping two equal digits, count only once.
Function
countDivisibleBy15(digits: int[]) → longExamples
Example 1
digits = [3,0,5,1]return = 10The digit sum is 9, a multiple of 3, so every arrangement is a multiple of 3. It is a multiple of 15 when it also ends in 0 or 5. Ending in 0, the digits 3, 5, 1 can go in front in 6 orders. Ending in 5, the digits 3, 0, 1 have 6 orders, but the 2 that start with 0 are not allowed, which leaves 4. The total is 10.
Example 2
digits = [1,2,4]return = 0No arrangement can end in 0 or 5, so none is divisible by 5.
Example 3
digits = [5,5,0,0,2]return = 15The digit sum is 12. Ending in 0, the rest 5, 5, 0, 2 have 4! / 2! = 12 different orders, 3 of which start with 0, leaving 9. Ending in 5, the rest 5, 0, 0, 2 have 12 orders, 6 of which start with 0, leaving 6. Swapping the two 5s or the two 0s gives the same number, so it is counted once. The total is 15.
Constraints
2 <= digits.length <= 150 <= digits[i] <= 9
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
- Best Single Reroll for Five DiceSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Revolver: Will the Next Shot Fire?Tower Research Capital · PHONE SCREEN
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Expected Fake-Name CollisionsMercor · PHONE SCREENMercor interview questions
- Election District Budget Allocation AnalysisIMC Trading · PHONE SCREENIMC Trading interview questions
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Extra Coin Win ProbabilityMicrosoft · PHONE SCREENMicrosoft interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions