← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round, one problem, pretty focused on the logic of filtering and arranging digits. Nothing fancy in terms of setup, just a straightforward algorithmic question that looks easy until you start thinking about edge cases.

Questions Asked (1)

Q1

Write a function that returns the smallest non-negative number that can be formed using only the odd digits from a given number. For example, given 12345, use only the digits 1, 3, and 5.

Algorithms & Data Structures
Author's notes

My first instinct was to sort the odd digits in ascending order and concatenate them, which works, but I spent too long second-guessing whether leading zeros could appear or whether the result should be zero if there are no odd digits at all.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient algorithm that extracts odd digits, sorts them in ascending order, and handles leading zeros. Discuss time and space complexity, and consider alternative approaches like counting sort for digits.

Pro tip: Mention that since digits are 0-9, a counting sort (frequency array) gives O(n) time, which is optimal. Also, explicitly handle the case where no odd digits exist by returning -1 or 0 as per requirements.

1. Clarify requirements and edge cases

Ask about input type (integer or string), output format, and behavior when no odd digits are present. Confirm if leading zeros are allowed (they are not, as the number would be smaller without them).

2. Extract odd digits

Iterate through the digits of the input number and collect all odd digits (1,3,5,7,9). This can be done by modulo 10 and division, or by converting to string.

3. Sort digits in ascending order

Sort the collected odd digits in non-decreasing order to form the smallest possible number. Use counting sort (frequency array of size 10) for O(n) time, or built-in sort for O(n log n).

4. Construct the smallest number

Concatenate the sorted digits. Since all digits are odd, there are no zeros, so no leading zero issue. If no odd digits, return -1 or 0 as agreed.

5. Analyze complexity and test

State time complexity O(n) with counting sort, space O(1) (fixed size array). Walk through examples like 12345 -> 135, and edge cases like 2468 (no odd digits) and 97531 -> 13579.

Key Points to Mention

  • Handling edge cases: no odd digits, single digit, negative numbers (if allowed), and very large numbers.
  • Choice of sorting algorithm: counting sort is optimal due to limited digit range (0-9).
  • Time and space complexity analysis: O(n) time, O(1) space with counting sort.
  • Avoiding leading zeros: not an issue here since odd digits exclude zero, but mention if zeros were included.
  • Clarifying return type: integer vs string, especially for large outputs that may exceed integer limits.
  • Testing with examples and edge cases to ensure correctness.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.