Misleading question description?

  • 0

    Input: "abb", "bab"
    Output: false
    Expected: true

    abb would have children of (a) and (bb) while bab would have children of (b) and (ab).

    so the only valid scrambled strings of "abb" would be "abb" and "bba".

    You can scramble string 2 and arrive at string 1, but not vice versa.

    If we are not constrained by only being able to scramble by swapping child nodes (ie, we can move letters back and forth between children - being able to swap from (a) and (bb) to (ab) and (b)) then that makes the problem significantly simpler. The problem description gave me the impression that the child swapping constraint was being imposed upon our definition of scramble.

  • 0

    I don't see any issue with the problem description. If abb is represented by a tree (ab) and (b), then you can swap the 2 children of the left sub-tree to arrive at (ba) and (b), i.e., bab.

  • 0

    Yeah, I closed it after reading the answer to the similar question and re-reading the problem description. I (and apparently some others) just glazed over the bit at the beginning stating that any two nonempty subtrees are a valid representation, and they were working through one possible representation. Thanks for the response.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.