Search⌘ K
AI Features

Solution: Scramble String

C# solution for the Scramble String problem using the Dynamic Programming pattern.

Statement

Given two strings s1 and s2 of equal length, determine whether s2 is a scrambled version of s1.

A string is considered a scramble of another if it can be produced by repeatedly applying the following process to any substring:
Choose an index to split the substring into two non empty parts, then either keep the two parts in the same order or swap them, and continue recursively on each part.

Return true if s2 can be obtained from s1 using this process, otherwise return false.

Constraints:

  • s1.length == s2.length

  • 11 \leq s1.length 30\leq 30 ...