Ctrl K

The Biggest Odd Chunk

Easy
You are given a string digits holding a large number with no leading zeros. You may cut out any contiguous non-empty piece of it and read that piece as a number. Return the piece that gives the largest odd number, or the empty string "" if no odd number can be formed. The string can be up to 10⁵ characters long, so converting whole pieces to integers is not a good idea.
Example 1
digits="73804" → '73'

A number is odd when its last digit is odd. The longest piece ending in an odd digit is "73".

Example 2
digits="2846" → ''

There are no odd digits at all, so the answer is empty.

Example 3
digits="901" → '901'
Constraints
  • 1 ≤ len(digits) ≤ 10⁵
  • digits contains only digits
  • digits does not start with a zero
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLargest Odd Bit Shuffle EasyYour Own Keypad Layout EasyRound Prices to a Total MediumCross Swaps of x and y MediumLucky Ticket With Blanks Medium
loading Python…
Input
digits="73804"
Expected
'73'

Run checks the first 3 tests in your browser. Submit checks all 132 tests on the server, hidden ones included.