Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Largest Odd Number in String

XPChallenge Points: 10
levelLevel: Easy

You are given a string num that represents a very large number.
Your task is to find the largest possible odd number that appears as a continuous substring of this string.

A substring means characters taken without skipping, directly next to each other.

If there is no odd digit anywhere in the string, return an empty string "".

Example 1:

Input: num = "7314"

Output: "731"

Explanation:

The odd substrings are "7", "73", "731", "3", etc. The largest odd number substring is 731.

Example 2:

Input: num = "8888"

Output: ""

Explanation:

All digits are even, so no odd substring exists.

Example 3:

Input: num = "12057"

Output: "12057"

Explanation:

The number already ends with an odd digit → entire string is odd.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result