InterviewDB
Experience
Parse Citations: Extract and Normalize Academic References from Text
phone
Interview Experience
Problem
You are given a block of text containing inline citations in the format [AuthorYear] (e.g., [Smith2019], [LeCun1989]). Extract all unique citations, parse them into structured form, and return them sorted by year then author.
python
import re
from dataclasses import dataclass
@dataclass
class Citation:
author: str
year: int
raw: str
def parse_citations(text: str) -> list[Citation]:
pass
**Input**:
"Recent work [Smith2019] builds on [LeCun1989] and [Vaswani2017].
See also [Smith2019] for further detail."
**Output**: [
Citation(author='LeCun', year=1989, raw='[LeCun1989]'),
Citation(author='Vaswani', year=2017, raw='[Vaswani2017]'),
Citation(author='Smith', year=2019, raw='[Smith2019]'),
]
# Deduplicated, sorted by year.
Follow-ups
- How would you extend the regex to handle multi-author citations like
[Smith&Jones2020]or[Smith et al. 2020]? - What if the year appears before the author (e.g.,
[2019Smith])? How do you detect the format? - How would you link each citation back to a list of references at the end of the document?
- Extend to extract citation context: the sentence in which each citation appears.
Full Details
Problem
You are given a block of text containing inline citations in the format [AuthorYear] (e.g., [Smith2019], [LeCun1989]). Extract all unique citations, parse them into structured form, and return them sorted by year then author.
python
import re
from dataclasses import dataclass
@dataclass
class Citation:
author: str
year: int
raw: str
def parse_citations(text: str) -> list[Citation]:
pass
**Input**:
"Recent work [Smith2019] builds on [LeCun1989] and [Vaswani2017].
See also [Smith2019] for further detail."
**Output**: [
Citation(author='LeCun', year=1989, raw='[LeCun1989]'),
Citation(author='Vaswani', year=2017, raw='[Vaswani2017]'),
Citation(author='Smith', year=2019, raw='[Smith2019]'),
]
# Deduplicated, sorted by year.
Follow-ups
- How would you extend the regex to handle multi-author citations like
[Smith&Jones2020]or[Smith et al. 2020]? - What if the year appears before the author (e.g.,
[2019Smith])? How do you detect the format? - How would you link each citation back to a list of references at the end of the document?
- Extend to extract citation context: the sentence in which each citation appears.
Free preview. Unlock all Moveworks questions →
About This Question
This is a candidate experience report from a moveworks interview during the phone round.
More Moveworks Interview Questions
LeetCode
#140 Word Break II
InterviewDB
Moveworks SWE Onsite - String Similarity (Strings/DP)
InterviewDB
Text Rewrite: Replace Words Using a Substitution Dictionary
LeetCode
#3076 Shortest Uncommon Substring in an Array
InterviewDB
Unique Substring: Find the Longest Substring with All Distinct Characters