Unique Digit Permutations Without Leading Zero
Updated
Problem statement
Given a nonempty decimal string digits, count the distinct permutations that use every occurrence exactly once and do not begin with 0.
Equal digits are indistinguishable. Return 0 when no valid permutation exists.
Function
countUniquePermutations(digits: String) → longExamples
Example 1
digits = "102"return = 4The valid permutations are 102, 120, 201, and 210.
Example 2
digits = "100"return = 1Only 100 is valid; permutations beginning with zero are excluded.
Example 3
digits = "000"return = 0Every arrangement begins with zero.
Constraints
1 <= digits.length() <= 20digitscontains only characters from0through9.- The answer fits in a signed 64-bit integer.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Generate One-Two Strings with Sum NGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Next Number with Disjoint DigitsElevenLabs · OAElevenLabs interview questions
- Permutations IILinkedIn · PHONE SCREENLinkedIn interview questions
- Unique String PermutationsAmazon · PHONE SCREEN
- Good SubsequencesNutanix · OANutanix interview questions
- Signed Digit Partitions Reaching a TargetMeta · PHONE SCREENMeta interview questions
- Even and Odd Digit Pattern ProbabilityJane Street · PHONE SCREENJane Street interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Generate Strings of Length at Least ThreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)