FunctionRacerProblemsRace

Custom Sort String

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

order has distinct lowercase letters and defines a custom alphabet: a letter that appears earlier in order is smaller. Return the letters of s sorted by this alphabet. Letters of s that are not in order go at the end, in alphabetical order.

Example 1

order "cba"
s "abcd"
returns "cbad"

c, b, a follow order, then the unlisted d: cbad.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems