Scramble String
Reported by candidates from Expedia's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure that decides this one is a memo table keyed on two substrings and a length. Expedia reported Scramble String in September 2026, and it looks scary because the recursion tree seems endless. It isn't. Strings cap at 30 characters, so a cached recursion finishes fast. You split, you either keep order or swap, and you ask whether both halves still match. If you blank on the structure during the live OA, StealthCoder sits invisibly on your desktop as a safety net and hands you the memoized solution. Know the shape before you open the invite.
The problem
A nonempty string can be recursively split into two nonempty parts; at any split, the two children may either keep their order or swap. Determine whether second can be produced from first by repeating this operation. Function isScramble(first: String, second: String) → boolean Examples Example 1 first = "great" second = "rgeat" return = true Case 1 exercises the documented deterministic contract. Example 2 first = "abcde" second = "caebd" return = false Case 2 exercises the documented deterministic contract. Example 3 first = "a" second = "a" return = true Case 3 exercises the documented deterministic contract. Constraints 1 <= first.length == second.length <= 30. Both strings contain lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a recursive check with memoization on (i, j, len), where i is the start in first, j is the start in second, and len is the segment length. For each split k from 1 to len-1, test two cases. No swap: first[i..k] matches second[j..k] and the remainders match. Swap: first[i..k] matches the tail of second's segment, and the remainders match crosswise. Base case: equal substrings return true. Prune early by comparing character counts, since different multisets can never scramble into each other. The common pitfall is skipping the cache, which blows up exponentially. Another is mixing up the swapped indices, so write them out on paper first. If the index math slips under pressure, StealthCoder is the hedge during the live OA, because it reads the problem and gives you working code without the proctor seeing anything.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Scramble String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as scramble string. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Expedia's OA.
Expedia reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Scramble String FAQ
What's the trick to Scramble String?+
Recursion plus memoization. Define a state as start in first, start in second, and length. Try every split point, checking both the keep-order and swap pairings. Cache each state so repeated subproblems cost nothing. Add a character-count check to prune impossible branches early.
How hard is this problem really?+
It's labeled hard, but the constraints are small, with length up to 30. The logic is a clean recursion once you see it. Most people lose points on the swapped index math, not the idea. A 3D DP or memoized recursion both pass comfortably.
Should I use top-down memo or bottom-up DP?+
Top-down is easier to write correctly under pressure. You mirror the problem statement directly and cache results in a map or 3D array. Bottom-up uses dp[len][i][j] and works too, but the loop ordering is easier to get wrong.
What edge cases break solutions?+
Equal strings must return true immediately. Single characters must compare directly. Strings with different letter counts must return false before recursing. Forgetting the swap case, or using wrong offsets for it, is the usual bug. Test with great and rgeat, then abcde and caebd.
How do I prepare for this in 48 hours?+
Write the memoized recursion from scratch twice without looking. Focus on the two split cases and their index offsets. Trace the great and rgeat example by hand. Then test a few duplicate-letter strings. Two clean runs beat reading five editorials.