Reorder a sequence of lecture topics so that they appear in the same order as an official reference list.
You are given a list of lecture topic names and another list that describes the desired order of those topics. Reorder the first list so that the topics appear in the order specified by the second list.
Each topic from the first list will appear exactly once in the reference order list, so the task is to map each topic to its position in the order list and sort accordingly. The relative order of topics not covered by the reference list is not relevant in this problem setup.
Input Format
- The input describes two ordered collections of strings.
- The first collection contains the lecture topics to be reordered.
- The second collection contains the reference order of all topics.
- Topic names are case-sensitive.
Output Format
- Output the lecture topics in the reordered sequence.
- Preserve the exact topic names from the input.
Constraints
- The number of topics is small to moderate.
- All lecture topics are assumed to be present in the reference order list.
- Topic names are unique within each collection.
Example 1
Input
topics = ["math", "algorithms", "dp"] order = ["dp", "math", "algorithms"]
Output
["dp", "math", "algorithms"]
Explanation
Each topic is assigned its index in the reference order: dp -> 0, math -> 1, algorithms -> 2. Sorting by those indices gives the required sequence.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.