← Expedia Interview InsightsSoftware Engineer
Use backtracking to replace each '?' with digits 0-8, pruning branches where the current sum plus the minimum possible sum of remaining '?' exceeds the target or plus the maximum possible sum is less than the target. Collect all valid strings when all '?' are replaced and the sum equals the target.
Pro tip: Clarify the constraints upfront (e.g., string length, number of '?', target range) and discuss time/space complexity; also mention that pruning with min/max remaining sums drastically reduces the search space.
Ask about input size, digit range (0-8), target sum range, and whether output order matters. Confirm that '?' can be replaced by any digit from 0 to 8.
Calculate the sum of fixed digits and count the number of '?' to determine the remaining sum needed and the min/max possible contributions from wildcards.
Recursively replace each '?' with digits 0-8, tracking current sum and index. Prune if current sum + minRemaining > target or current sum + maxRemaining < target.
When all '?' are replaced, check if the total sum equals the target; if so, add the string to the result list. Return the list of all valid strings.
Discuss time complexity (worst-case O(9^k) where k is number of '?') and space complexity (O(k) recursion depth). Mention that pruning reduces practical runtime.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.