def custom_sort(order, target):
Two first-hand onsite reports. You get two strings. One, order, gives every character's rank; one candidate likened it to the alien-dictionary problem. Rearrange the characters of the other string, target, by that order. One report says the sort had to run in linear time; that candidate did not get to a linear sort and was rejected.
Part 1 — Sort a string by a custom order
Write custom_sort(order: str, target: str) -> str.
order lists characters from first to last, with no repeats.target rearranged so that every character comes before any character ranked after it in order. Repeated characters all stay.target appears in order (the tests keep to that; ask what to do otherwise).The function name and argument order are our setup: the two reports list the inputs in different orders.
Two Waymo onsite reports. One candidate says both coding rounds were not hard, but they did not get the first one, this custom sort, to linear time; they were rejected within a week with no detailed feedback. The other report lists it among the onsite coding questions without more detail. Neither report describes follow-up questions.
Two first-hand onsite reports. You get two strings. One, order, gives every character's rank; one candidate likened it to the alien-dictionary problem. Rearrange the characters of the other string, target, by that order. One report says the sort had to run in linear time; that candidate did not get to a linear sort and was rejected.
Part 1 — Sort a string by a custom order
Write custom_sort(order: str, target: str) -> str.
order lists characters from first to last, with no repeats.target rearranged so that every character comes before any character ranked after it in order. Repeated characters all stay.target appears in order (the tests keep to that; ask what to do otherwise).The function name and argument order are our setup: the two reports list the inputs in different orders.
| Approach | Notes |
|---|---|
| Comparison-based sort with custom comparator | Simple to implement — build a rank map then sort target using that map as the comparator key. Time complexity is O(n log n), which does not meet the linear time requirement. |
Common mistakes: One candidate did not get the sort to linear time and was rejected within a week, with no detailed feedback.
Interviewer hints: One report says linear sorting time was required.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.