Problem Description
Given a string word consisting of digits and lowercase English letters, replace every non-digit character with a space. Then extract the integers (separated by at least one space) and ignore numbers that are the same after removing any leading zeros. Return the count of unique integers.
Key Insights
- Replace all non-digit characters in the string with spaces.
- Split the string using spaces to get the number substrings.
- Remove leading zeros by converting each substring to an integer.
- Use a set to track unique integers.
Space and Time Complexity
Time Complexity: O(n), where n is the length of the string, due to scanning and processing each character. Space Complexity: O(n), in the worst-case scenario where all characters form unique numbers.
Solution
The solution involves iterating over the input string and converting letters to spaces to isolate numeric sequences. After splitting the modified string into substrings, each substring is normalized by converting to an integer (thereby removing any leading zeros) and converting back to a string. These normalized number strings are stored in a set to ensure uniqueness. Finally, the size of the set, representing the number of unique integers, is returned.