Strings String basics
125. Largest Odd Number in String
You are given a string num that holds a large integer, one digit per character. Return the largest odd
integer that appears as a substring of num, as a string. If no substring is an odd integer, return the
empty string.
A substring is a run of one or more characters that sit next to each other in num. The substrings of
"352" are "3", "5", "2", "35", "52" and "352".
Answers are shown in double quotes, so an empty answer shows as "".
Example 1
Input: num = "583914"
"58391"Explanation: The whole number, 583914, is even. The largest odd number among its substrings is 58391.
Example 2
Input: num = "2460"
""Explanation: Every substring is an even number, so the answer is the empty string.
Example 3
Input: num = "10200"
"1"Explanation: Zero counts as even. The only odd number among the substrings is 1.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ num.length ≤ 105numholds only the digits0to9.numhas no leading zeros: it starts with0only when it is"0".
Clarifying questions
What you would ask an interviewer before writing any code.