#11Alien DNA Transformation
Scientists have discovered a process for transforming an alien DNA sequence.
A DNA sequence can be reconfigured using the following rules:
If the sequence has only one character, stop. If the sequence has more than one character: Split it at any position into two non-empty parts. Either keep the two parts in the same order or swap their positions. Recursively apply the same process to both parts.
Given two DNA sequences dna1 and dna2 of the same length, return true if dna2 can be obtained by reconfiguring dna1. Otherwise, return false.
Examples
Example 1
Input: dna1 = "planet", dna2 = "pnalet"
Output: true
Explanation: Explanation: One possible transformation is: "planet" → "pl / anet" → "p / l / anet" → "l / p / anet" → "lp / anet" → ... After recursively splitting and optionally swapping parts, "pnalet" can be formed.
Example 2
Input: dna1 = "coding", dna2 = "gcodin"
Output: false
Explanation: No valid sequence of recursive splits and swaps can transform "coding" into "gcodin".
Example 3
Input: dna1 = "z", dna2 = "z"
Output: true
Explanation: A single-character sequence is already unchanged.
Constraints
- dna1.length == dna2.length
- 1 <= dna1.length <= 35
- dna1 and dna2 consist only of lowercase English letters.
- Both sequences may contain repeated characters.
