← 返回 perplexity 的题目列表Parse citation numbers from paragraphs and reorder/deduplicate sources by first appearance
类型:online_judge
Problem: Extract citation numbers from paragraphs and deduplicate/reorder sources by first appearance
You are given:
paragraphs: an array of text paragraphs. Each paragraph may contain zero or more citation numbers in a fixed textual pattern. Each citation number maps to an entry in sources.
sources: a list/array of sources, where a citation number maps to a source entry (either 0- or 1-based as specified).
Task 1
Output all citation numbers that appear in paragraphs.
The same citation may appear multiple times across paragraphs.
The prompt does not specify whether to deduplicate/sort; if unspecified, clarify whether to preserve appearance order or return a set.
Task 2
Deduplicate sources and reorder them by the order in which their citations first appear in paragraphs, producing a new list sources'.
Dedup rule: if multiple citation numbers refer to the same source, keep only one.
Ordering rule: order sources by the first time they are referenced in paragraphs.
Note: The original description does not say whether you must also renumber citations in the paragraphs (and/or output an old->new mapping). If required, additionally produce the mapping and updated paragraphs.
Constraints
Not provided in the original post; clarify during the interview.
Example (illustrative)
Assume citations look like [n].
paragraphs = ["A[2] B[1]", "C[2] D[3]"]
sources = ["src1", "src2", "src2", "src3"]
Task 1 output: [2, 1, 2, 3] (or deduped [2,1,3] depending on requirements)
Task 2 output: sources ordered by first appearance of their citations: 2 -> 1 -> 3, then deduped.
Example
Input
[]
[]
Output
citations=[]
new_sources=[]