You are given a non-negative integer n. Your task is to return its smallest and second-smallest distinct digits.
The digits must be distinct, meaning repeated occurrences of the same digit count only once. Return the two smallest different digits in ascending order.
Input: n = 3852
Output: smallest = 2, second = 3
Explanation: The two smallest distinct digits are 2 and 3.
Input: n = 91019
Output: smallest = 0, second = 1
Explanation: The distinct digits are 0, 1, and 9, so the two smallest are 0 and 1.
Input: n = 4321
Output: smallest = 1, second = 2
Explanation: The two smallest distinct digits are 1 and 2.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
120
0 1
345
3 4