266. Scramble String

HardStringString

We can scramble a string s by recursively partitioning it into two non-empty substrings and optionally swapping them, then scrambling each part. Given two strings s1 and s2 of equal length, return true if s2 is a scrambled version of s1. Input: '"s1", "s2"'.

Input: '"s1", "s2"'.

Output: Boolean — true or false.

Examples

Example 1
Input: "great", "rgeat"
Output: true
Explanation: Valid scramble via swaps.
Example 2
Input: "abcde", "caebd"
Output: false
Explanation: Not a valid scramble.
Example 3
Input: "a", "a"
Output: true
Explanation: Trivial.

Constraints

Asked by

AmazonGoogleBloombergMeta
Solve this problem in the editor →