FastPrepUnique Digit Permutations Without Leading Zero
Problems/Unique Digit Permutations Without Leading Zero

Unique Digit Permutations Without Leading Zero

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Software Engineer IC2 interview report described counting unique permutations when digits repeat and a number may not start with zero. The report left out how the input is given and the limits. Here, the input is a digit string and the answer fits in a safe 64-bit number. Our version is about 88% the same as the reported question.

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

Examples

Example 1

digits = "102"return = 4

The valid permutations are 102, 120, 201, and 210.

Example 2

digits = "100"return = 1

Only 100 is valid; permutations beginning with zero are excluded.

Example 3

digits = "000"return = 0

Every arrangement begins with zero.

Constraints

  • 1 <= digits.length() <= 20
  • digits contains only characters from 0 through 9.
  • 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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long countUniquePermutations(String digits) {
      // write your code here
    }
}
Checking account…