As reported: D. E. Shaw Quality and Test Engineer interview (April 2025): one of four DSA problems given as LeetCode links — Scramble String.
This is LeetCode 87 — Scramble String. Our write-up: /scramble-string.
A string s is scrambled as follows: if its length is 1, stop. Otherwise split it at any point into non-empty x and y (s = x + y), optionally swap them (s = y + x), and scramble x and y recursively.
Given s1 and s2 of equal length, return true if s2 is a scrambled string of s1.
Example 1
s1 = "great", s2 = "rgeat"
Output: true
Example 2
s1 = "abcde", s2 = "caebd"
Output: false
Example 3
s1 = "a", s2 = "a"
Output: true
Constraints: s1.length == s2.length; 1 ≤ s1.length ≤ 30; lowercase English letters.
Code runner format: one JSON value per line: s1, then s2. Implement isScramble(s1, s2).