1903. Largest Odd Number in String
Intuition
To find the largest-valued odd integer substring, we don't need to check every possible substring. Since the original string represents a number and all digits are ordered from most significant to least significant (like a real number), the largest odd-valued substring will simply be the longest prefix (from the start) ending at the rightmost odd digit.
If we find the last odd digit in the string while iterating from the end, the substring from the start to that index will be our answer.
Complexity
Space Complexity
Time Complexity
Code
Last updated