Largest Odd Number in String

Easy Topics Company Tags

num contains the decimal digits of a large integer. Among all nonempty contiguous substrings representing odd integers, return the one with the greatest numeric value as a string. If none exists, return an empty string. The input may be too large for a fixed-width integer.

Example 1:

Input: num = "0"

Output: ""

Explanation: The only nonempty substring is "0", which is even. No odd number can be selected.

Example 2:

Input: num = "1"

Output: "1"

Explanation: The whole string represents the odd number 1.

Example 3:

Input: num = "2"

Output: ""

Explanation: The only nonempty substring is "2", which is even, so the answer is an empty string.

Constraints:

  • 1 <= num.length <= 100000
  • Only decimal digits occur, with no leading zeros.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.