Problem 711
Largest Odd Number in a String
Easy · 10 pts · String, Greedy
Problem
You are given a large integer as a string of digits with no leading zeros. Find the largest odd integer that is a non-empty substring (a block of consecutive digits) of it, and print it, or print -1 if there is none. An odd number ends with an odd digit, and among substrings the longest one starting at the beginning is the largest, so the answer is the prefix ending at the last odd digit.
Input
A single string NUM of digits without leading zeros.
Output
Print the largest odd substring, or -1.
Constraints
1 <= |NUM| <= 100000
Example input
35427
Example output
35427
Explanation
In 35427 the last odd digit is the final 7, so the whole number 35427 is odd and is the answer. For 4206 there is no odd digit, so the answer would be -1.