← Airbnb Interview Insights

Airbnb·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Airbnb software engineer interview with a digit rearrangement problem that started simple enough but had a follow-up that really tested whether you'd thought through edge cases. Pretty algorithmic, not much systems stuff.

Questions Asked (2)

Q1

Given a non-negative integer, rearrange its digits to produce the smallest possible number. Leading zeros are permitted in the result.

Algorithms & Data Structures
Author's notes

Sorting the digits ascending is the obvious move and I got there fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Convert the integer to a string, sort its digits in ascending order, and then join them back to form the smallest number. Since leading zeros are allowed, the result may have leading zeros, which is acceptable. This approach is straightforward and efficient with O(n log n) time complexity due to sorting.

Pro tip: Clarify that leading zeros are allowed, so no special handling is needed; if they weren't, you'd need to find the smallest non-zero digit to place first. Also, mention that the result might be a string if leading zeros are present, but if an integer is required, you can convert it back (though leading zeros would be lost).

1. Understand the problem

Confirm that the input is a non-negative integer and that leading zeros are permitted in the output. Ask if the output should be an integer or a string, as leading zeros affect representation.

2. Choose data structure

Convert the integer to a string or list of characters to easily manipulate individual digits. Sorting is the key operation.

3. Sort digits

Sort the digits in ascending order. This places the smallest digits first, which minimizes the overall number when concatenated.

4. Construct result

Join the sorted digits to form the smallest number. If leading zeros are allowed, simply return the string; otherwise, handle the first non-zero digit.

5. Analyze complexity

State that the time complexity is O(n log n) due to sorting, where n is the number of digits, and space complexity is O(n) for the string/list.

Key Points to Mention

  • Sorting digits in ascending order yields the smallest permutation.
  • Leading zeros are allowed, so no special handling is required.
  • Time complexity: O(n log n) due to sorting; space complexity: O(n).
  • Edge cases: single-digit numbers, numbers with zeros, and all zeros.
  • If leading zeros were not allowed, find the smallest non-zero digit to place first.
  • The result may be represented as a string to preserve leading zeros.

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

Q2

Follow-up: given the same integer and an additional lower bound, find the smallest rearrangement of the digits that is strictly greater than the lower bound, or report that no such rearrangement exists.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I started second-guessing myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then propose an algorithm that finds the smallest permutation of the digits that is strictly greater than the lower bound. A common efficient approach is to sort the digits and use backtracking with pruning, or to generate permutations in lexicographic order and pick the first that exceeds the bound.

Pro tip: Mention that if the number of digits is large, generating all permutations is infeasible, so pruning based on the lower bound is crucial. Also, consider if the lower bound has more digits than the integer, then no rearrangement can be greater, so return 'none'.

1. Clarify constraints and edge cases

Ask about the range of the integer, the lower bound, and whether the rearrangement must use all digits exactly once. Discuss cases like leading zeros, negative numbers, and when the lower bound has more digits.

2. Choose an algorithm

Decide between generating all permutations and sorting, or using a more efficient approach like backtracking with pruning. Consider time and space complexity trade-offs.

3. Implement the solution

Write code to generate permutations in lexicographic order, compare with the lower bound, and return the first valid one. Ensure to handle duplicates if digits repeat.

4. Test with examples

Walk through examples like integer=123, lowerBound=200 (answer: 213) and integer=123, lowerBound=321 (answer: none). Also test edge cases like single digit, repeated digits, and leading zeros.

5. Analyze complexity and optimize

Discuss the time complexity (e.g., O(n! * n) for brute force) and suggest optimizations like pruning branches that cannot exceed the bound, or using next permutation algorithm.

Key Points to Mention

  • Handling duplicates in digits to avoid redundant permutations
  • Leading zeros: a rearrangement cannot have leading zeros unless the number is zero
  • Comparison with lower bound: need to compare as integers or strings of equal length
  • Edge case: lower bound has more digits than the integer, so no solution
  • Time complexity and potential optimizations like pruning or using next permutation
  • Return value: specify what to return if no rearrangement exists (e.g., null, -1, or a message)

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