FastPrepScramble String

Scramble String

Expedia logoExpedia● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

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.

More Expedia problems

See Expedia hiring insights
public boolean isScramble(String first, String second) {
    // Write your code here.
}
first"great"
second"rgeat"
expectedtrue
Checking account…