Check If String Is Transformable With Substring Sort Operations
Given two strings s and t, transform string s into string t using the following operation any number of times:
- Choose a non-empty substring in
sand sort it in place so the characters are in ascending order.
Return true if it is possible to transform s into t. Otherwise, return false.
A substring is a contiguous sequence of characters within a string.
Example 1
Input
s = "84532", t = "34852"Output
trueYou can transform
s into t by sorting substrings from indices 2 to 3 and then 0 to 2.Example 2
Input
s = "34521", t = "23415"Output
trueYou can transform
s into t using substring sort operations: "34521" becomes "23451", then "23415".Constraints
- s.length == t.length
- 1 <= s.length <= 10^5
- s and t consist of only digits.