#1585
Check If String Is Transformable With Substring Sort Operations
candidate master · 1395 · lc hard +32 · verified · 51.2% accepted · 456 likes · top 40%
Description
Given strings s and t, you can transform s by repeatedly choosing any non-empty substring and sorting it in ascending order. Return true if s can be transformed into t through any number of such operations, otherwise return false.
Example 1:
Input: s = "84532", t = "34852"
Output: true
Explanation: You can transform s into t using the following sort operations:
"84532" (from index 2 to 3) -> "84352"
"84352" (from index 0 to 2) -> "34852"
Example 2:
Input: s = "34521", t = "23415"
Output: true
Explanation: You can transform s into t using the following sort operations:
"34521" -> "23451"
"23451" -> "23415"
Example 3:
Input: s = "12345", t = "12435"
Output: false
Code
1
2
3