A design tool can shuffle a text label with this recursive rule. A label of one letter stays as it is. A longer label is cut into two non-empty parts at any point; the two parts may be swapped or left in place; then each part is shuffled again with the same rule.
Write isShuffledLabel(original, shuffled) that returns true if shuffled can be produced from original by this rule, and false otherwise.
Input: original = "panel", shuffled = "nelap" Output: true
Cut panel into pa + nel and swap the parts, then cut pa into p + a and swap those.
Input: original = "chart", shuffled = "rcath" Output: false
No sequence of cuts and swaps produces it.
1 <= original.length <= 30shuffled.length === original.lengthRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #490 Shuffled Label Check. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.