1174. Scramble String

EasyDynamic ProgrammingSequence DP

A string can be scrambled by recursively splitting it into two non-empty parts and optionally swapping them. Given s1 and s2 of equal length, determine whether s2 is a scramble of s1. Return true or false. The input is JSON {s1, s2}.

Input: JSON {s1, s2}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s1":"great","s2":"rgeat"}
Output: true
Explanation: A valid scramble.
Example 2
Input: {"s1":"abcde","s2":"caebd"}
Output: false
Explanation: Not a scramble.
Example 3
Input: {"s1":"a","s2":"a"}
Output: true
Explanation: Identical single characters.

Constraints

Asked by

AmazonGoogleBloombergMeta
Solve this problem in the editor →