← Expedia Interview Insights

Expedia·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Three coding problems for a software engineer role at Expedia. Nothing too wild but the second one on palindrome substrings had me second-guessing my approach the whole time.

Questions Asked (3)

Q1

Implement the run-length spoken sequence: starting from "1", each next term is built by reading the previous string and describing consecutive groups of identical digits as count-then-digit. Return the nth term.

Algorithms & Data Structures
Author's notes

Pretty mechanical once you see the pattern.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the sequence starts with '1' as the first term, then iteratively generate each next term by scanning the previous string and appending the count and digit for each run of identical digits. Implement this with a simple loop that builds the next term from the current one, repeating n-1 times, and discuss time/space complexity.

Pro tip: Mention that the sequence grows exponentially (about 1.3^n), so for large n you should consider memory limits and possibly generate the nth term without storing all previous terms. Also, clarify edge cases like n=1 and n=0 upfront.

1. Clarify the problem and edge cases

Confirm that the first term is '1' and that we need to return the nth term. Ask about constraints (e.g., maximum n) and handle edge cases like n=0 or n=1.

2. Design the iterative approach

Start with the current term as '1'. For each step from 2 to n, scan the current term, count consecutive identical digits, and build the next term by appending count followed by digit.

3. Implement the run-length encoding

Use a loop with a pointer to traverse the string, tracking the current digit and its count. When the digit changes, append the count and digit to a result list, then reset for the new digit.

4. Analyze complexity and optimize

Discuss that time complexity is O(total length of all terms up to n), which is exponential in n. Mention that space can be optimized to O(length of current term) by only keeping the previous term.

5. Test with examples

Walk through small n (e.g., n=1 -> '1', n=2 -> '11', n=3 -> '21', n=4 -> '1211') to verify correctness and edge cases.

Key Points to Mention

  • The sequence is known as the look-and-say sequence; starting with '1' gives the standard sequence.
  • Run-length encoding: count consecutive identical digits and describe as count then digit.
  • Iterative generation avoids recursion overhead and is straightforward.
  • Time complexity is exponential in n due to string growth; space can be O(length of current term).
  • Edge cases: n=1 returns '1'; n=0 may be invalid or return empty string depending on definition.
  • Potential optimization: use a list of characters or StringBuilder for efficient string concatenation.

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

Q2

Given a list of lowercase strings, for each string count how many non-empty contiguous substrings can be rearranged into a palindrome. For example, "aabb" gives 9.

Algorithms & Data Structures
Author's notes

This one tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem and edge cases, then explain the key insight: a string can be rearranged into a palindrome if at most one character has an odd frequency. Use a bitmask to represent the parity of character counts, and for each string, count substrings with at most one set bit using a hash map of prefix masks.

Pro tip: Mention that the bitmask approach works because there are only 26 lowercase letters, so the mask fits in an integer. Also, note that the solution runs in O(n) per string, which is optimal for this problem.

1. Clarify the problem

Confirm that substrings are contiguous, non-empty, and that rearrangement means any permutation of the characters. Ask about input size and constraints to determine the expected complexity.

2. Identify the palindrome condition

Explain that a string can be rearranged into a palindrome if and only if at most one character has an odd count. This is the key property to check for each substring.

3. Use prefix parity masks

Represent the parity of character counts as a 26-bit integer. Compute prefix masks for each position, where the mask at index i represents the parity of characters in the substring from start to i.

4. Count valid substrings with a hash map

For each prefix mask, count how many previous prefix masks differ by at most one bit (i.e., have Hamming distance 0 or 1). Use a hash map to store frequencies of prefix masks and iterate through the string.

5. Analyze complexity and edge cases

State that the time complexity is O(n) per string and space O(n) for the hash map. Discuss edge cases like empty strings, single characters, and strings with all identical characters.

Key Points to Mention

  • Palindrome rearrangement condition: at most one character with odd frequency.
  • Bitmask representation of character parity (26 bits).
  • Prefix XOR to compute parity of any substring.
  • Hash map to count occurrences of each mask.
  • Checking masks that differ by exactly one bit (or zero bits).
  • Time and space complexity: O(n) time, O(n) space per string.

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

Q3

Given a numeric string with some positions marked as '?', a target digit sum, and a constraint that each '?' can only be replaced by digits 0 through 8, return all completed strings whose digits sum to the target.

Algorithms & Data Structures
Author's notes

Backtracking, pretty standard.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use backtracking to explore all possible digit assignments for '?' positions, pruning branches where the current sum plus the minimum possible remaining sum exceeds the target or the maximum possible remaining sum falls short. For each complete assignment, check if the total sum equals the target and add the resulting string to the output. This ensures efficiency by avoiding unnecessary recursion.

Pro tip: Precompute the sum of fixed digits and the number of '?' positions to quickly determine if a solution is possible (target must be between fixedSum and fixedSum + 8*numQuestionMarks). Also, during backtracking, prune early by checking if the remaining sum can be achieved with the remaining '?' positions.

1. Parse and Preprocess

Calculate the sum of fixed digits and count the number of '?' positions. Check if the target sum is within the feasible range [fixedSum, fixedSum + 8 * numQuestionMarks]; if not, return an empty list immediately.

2. Backtracking Setup

Convert the string to a list of characters for easy modification. Define a recursive function that takes the current index, the current sum, and the list of characters.

3. Recursive Exploration with Pruning

At each '?' position, iterate digits 0-8. For each digit, update the sum and recurse. Prune if the current sum plus the minimum possible sum from remaining '?' (0 each) exceeds the target, or if the current sum plus the maximum possible sum from remaining '?' (8 each) is less than the target.

4. Base Case and Result Collection

When all positions are processed, if the current sum equals the target, convert the character list back to a string and add it to the results list.

5. Return Results

After the recursion completes, return the list of valid completed strings.

Key Points to Mention

  • Backtracking as the core algorithm for exploring all combinations.
  • Pruning techniques to reduce unnecessary recursive calls, such as checking min/max possible sums.
  • Time complexity analysis: O(9^k) worst-case, where k is the number of '?' positions, but pruning improves practical performance.
  • Space complexity: O(k) for recursion stack and O(m) for output storage, where m is the number of valid strings.
  • Handling edge cases: no '?' positions, target sum unreachable, or target sum exactly achievable.
  • Digit constraint: only digits 0-8 are allowed, which affects the maximum possible sum.

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