Sort the letters in the string
s by the order they occur in the string
s = "weather"and
t = "therapyw", the output should be
sortByString(s, t) = "theeraw";
s = "good"and
t = "odg", the output should be
sortByString(s, t) = "oodg".
- [time limit] 4000ms (py)
- [input] string s
A string consisting only of lowercase English letters.
0 ≤ s.length ≤ 104.
- [input] string t
A string consisting only of unique lowercase English letters. It is guaranteed that
tcontains all of the letters that occur in
0 ≤ t.length ≤ 26.
- [output] string
We have a string input, using a custom lambda function that uses the indexes of letters in the second string (using find function,) we sort the letters. sorted function returns an array and we need to convert it to a string. We do this by calling join without putting any delimiters.