RAG Citation Text Matching and Tagging
Harvey AI interview questions · Hard · Coding round · reported 19× · 6 tests
You are given an LLM answer string and a list of source phrases. Implement a function that does two things:
- Report, for every source phrase, the number of times it occurs in the text.
- Return the text with every matched region wrapped in
<yellow>...</yellow>, followed by citation indices such as[0][2].
Function signature
function annotateCitations(
text: string,
sources: string[],
): { counts: number[]; taggedText: string }Run your code with Ctrl+Enter to see results.