Solve three interview coding problems
Company: Expedia
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This multi-part question evaluates string manipulation, combinatorial counting, and constrained enumeration skills through sequence generation, palindromic-anagram substring counting, and wildcard digit-sum completion tasks.
Part 1: Generate a Run-Length Spoken Sequence
Constraints
- 1 <= n <= 25
- The answer fits in memory.
Examples
Input: 1
Expected Output: "1"
Explanation: Edge case: the first term is the starting value itself.
Input: 2
Expected Output: "11"
Explanation: Read "1" as one 1.
Hints
- Build the sequence iteratively from term 1 up to term n.
- When converting one term into the next, count consecutive equal digits with a loop or two pointers.
Part 2: Count Substrings That Can Be Rearranged Into a Palindrome
Constraints
- 0 <= len(strings) <= 10^4
- 0 <= len(s) for each s in strings
- Sum of lengths of all strings <= 2 * 10^5
- Each string contains only characters 'a' to 'z'
Examples
Input: ["aabb"]
Expected Output: [9]
Explanation: There are 9 non-empty substrings of "aabb" that can be rearranged into a palindrome.
Input: ["abc", "aaaa"]
Expected Output: [3, 10]
Explanation: "abc" contributes only its three single-character substrings. Every non-empty substring of "aaaa" works, so its count is 10.
Hints
- A multiset of characters can form a palindrome if at most one character has odd frequency.
- Use a prefix parity bitmask: two prefixes define a valid substring when their masks are equal or differ by exactly one bit.
Part 3: Replace Wildcards to Match a Digit Sum
Constraints
- 0 <= len(pattern) <= 15
- pattern contains only characters '0' to '9' and '?'
- 0 <= target <= 9 * len(pattern)
- Each '?' may only be replaced with a digit from 0 to 8
Examples
Input: ("08??840", 24)
Expected Output: ["0804840", "0813840", "0822840", "0831840", "0840840"]
Explanation: The fixed digits sum to 20, so the two wildcards must add up to 4.
Input: ("5?1", 7)
Expected Output: ["511"]
Explanation: The fixed digits already sum to 6, so the wildcard must be 1.
Hints
- First compute the sum of the fixed digits, then only distribute the remaining sum across the '?' positions.
- Use backtracking, but prune branches when the remaining sum is too small or too large for the remaining wildcard slots.