You are given a string s and two distinct lowercase English letters x and y.
Rearrange the characters of s to construct a new string t such that:
t is a permutation of s.y appears before every occurrence of x in t.Return any valid string t.
Example 1:
Input: s = "aabc", x = "a", y = "c"
Output: "cbaa"
Explanation:
The string "cbaa" is a permutation of "aabc", and every occurrence of 'c' appears before every occurrence of 'a'.
Example 2:
Input: s = "dcab", x = "d", y = "b"
Output: "cabd"
Explanation:
The string "cabd" is a permutation of "dcab", and every occurrence of 'b' appears before every occurrence of 'd'.
Example 3:
Input: s = "axe", x = "o", y = "x"
Output: "axe"
Explanation:
The string "axe" is already valid. Since 'o' does not occur in the string, the required condition is automatically satisfied.
Constraints:
1 <= s.length <= 100s consists of lowercase English letters.x and y are lowercase English letters.x != yOnly the relative order between occurrences of x and y matters.
One approach is to place all occurrences of y before all other characters, and place all occurrences of x after them.
Another approach is to sort the characters of s. If x < y, sort in descending order; otherwise, sort in ascending order.
After sorting this way, every occurrence of y will appear before every occurrence of x.
"aabc" "a" "c"
"dcab" "d" "b"
"axe" "o" "x"