Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Smallest number from odd digits

Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 8 minutes. Part of the Pro drill bank.

Keep the odd digits of a number and arrange them into the smallest possible number. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement smallest_odd(n: int) -> int. Take the odd digits (1, 3, 5, 7, 9) of n, using every odd digit exactly as often as it occurs, and arrange them to form the smallest possible number. Ignore the sign of n. Return -1 if n has no odd digit.

Requirements

  • Return an int, not a string.

Constraints

  • n fits in a 64-bit integer.
  • n can be negative or zero.

Examples

Input: smallest_odd(5231) Output: 135 The odd digits are 5, 3 and 1; ascending they form 135.

Topics: lakebench, python, digits, sorting.

More Python interview questions · All interview problems · Learn data engineering

beginner

Smallest number from odd digits

Interview-style drill: Keep the odd digits of a number and arrange them into the smallest possible number.

Implement `smallest_odd(n: int) -> int`. Take the odd digits (1, 3, 5, 7, 9) of `n`, using every odd digit exactly as often as it occurs, and arrange them to form the smallest possible number. Ignore the sign of `n`. Return `-1` if `n` has no odd digit. Example: `5231` has odd digits 5, 3 and 1, and the smallest number from them is `135`.