Design Gurus Logo
Largest Odd Number in String (easy)

Problem Statement

Given a large integer num represented as string, return the largest-valued odd integer (represented as a string) that is a non-empty substring of num. If no such number exists, the result should be an empty string.

A substring is defined as a contiguous sequence of characters within a string.

Examples

  • Example 1:

    • Input: num = "238946"
    • Expected Output: "2389"
    • Justification: The largest odd number in the string is "2389".
  • Example 2:

    • Input: num = "2804"
    • Expected Output: ""
    • Justification: Since there are no odd numbers in the input string, the output is an empty string.
  • Example 3:

    • Input: num = "13579"
    • Expected Output: "13579"
    • Justification: The entire input string is the largest odd number itself, as all digits are odd.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory