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 s and 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
Inputs = "84532", t = "34852"
Outputtrue
You can transform s into t by sorting substrings from indices 2 to 3 and then 0 to 2.
Example 2
Inputs = "34521", t = "23415"
Outputtrue
You 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.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate