CodingPhone, OnsiteSoftware Engineer, Machine Learning EngineerLast reported March 2026Low Frequency
Problem Overview
Given two input strings: `order` and `target`.
Full problem statement
Given two input strings: `order` and `target`. The `order` string defines a custom character ordering (similar to the alien dictionary problem). Sort the characters in `target` according to the precedence defined by `order`. The solution is expected to run in linear time O(n) with respect to the length of `target`.
Follow-up Arc
Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion
Can you achieve linear time complexity O(n)?
Probes for: Candidate produces a working solution
What if there are characters in target that don't appear in order? How do you handle them?
Probes for: Candidate explains the approach
Approach Trade-offs
Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
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.
Practice
Open the editor to write a solution against test cases, then return here to compare against the follow-ups.