Trains the technique from
LeetCode 1903Largest Odd Number in StringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A part carries a serial num, written as a run of decimal digits.
A segment of the serial is any unbroken stretch of one or more of those digits, read in the order they are printed. Each segment stands for a whole number; a segment that begins with a zero simply stands for a smaller number.
Among the segments whose value is odd, find the one of greatest value and return it as a string, digit for digit as it is printed on the part. When no segment of the serial is odd, return the empty string.
Example 1
The segment "91" stands for the odd number 91. The only segments of this serial standing for a larger number are "914", "9146" and "146", and none of those three is odd.
Example 2
Every digit printed here is even, so every segment ends in an even digit and no segment is odd.
Example 3
The whole serial is itself a segment, it stands for 8003, and 8003 is odd. No segment of this serial stands for a larger number.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def largest_odd_number(num: str) -> str:public String largestOddNumber(String num)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.