Ctrl K

Distinct Numbers in a Text

Easy
The string text consists of lowercase English letters and digits. Every unbroken run of digits forms one number; letters only separate the numbers. Two numbers count as the same if they have the same value: leading zeros do not matter, so 7, 07 and 007 are all one number. Return how many distinct numbers appear in the text.
Example 1
text="room12floor7room012" → 2

The numbers are 12, 7 and 012. Leading zeros are ignored, so 012 is the same as 12: two distinct numbers.

Example 2
text="x0y00z5" → 2

0 and 00 are both zero, plus 5: two in total.

Example 3
text="nodigits" → 0
Constraints
  • 1 ≤ len(text) ≤ 1000
  • text consists of lowercase English letters and digits
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySame Letter Cipher EasySame Letters, Reshuffled EasySame When Flipped EasyShuffle Into a Palindrome Easy
loading Python…
Input
text="room12floor7room012"
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.