Produce a Word-Level Redline Between Two Clause Versions
Last updated: November 29, 2026
Quick Overview
Given the original and revised text of a contract clause, compute a minimal word-level redline as a sequence of equal, delete and insert runs, and render it in a simple markup.
Legora
November 29, 20260
0
0 solved
Given the original and revised text of a contract clause, compute a minimal word-level redline as a sequence of equal, delete and insert runs, and render it in a simple markup.
Lawyers judge an AI drafting tool by its redlines, and Legora's Word add-in shows suggested changes as tracked edits. In an onsite coding round this checks that you can build an LCS-based diff, group the output into readable runs, and reason about its quadratic cost on long clauses.
What the Interviewer Expects
- Tokenises into words and punctuation rather than characters
- Builds an LCS table and walks it to produce edit operations
- Merges consecutive operations of the same type into runs
- Handles empty inputs and identical inputs
- States O(n*m) time and space and knows when that hurts
- Mentions Myers or patience diff as the production option
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you cut memory to O(min(n, m)) while still recovering the edit script?
- Patience diff often reads better for lawyers; why, and when would you use it?
- How would you preserve original whitespace and formatting runs when writing tracked changes into a .docx?
- How would you show a moved paragraph as a move rather than delete plus insert?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Granularity is words, with punctuation as separate tokens so 30 days. to 45 days. changes only the number. Output is a list of (op, text) runs where op is equal, delete or insert, ordered ...
High-Level Design
Tokenise both strings. Fill a suffix LCS table dp[i][j]. Walk from (0,0): equal tokens advance both; otherwise move in the direction that keeps the larger LCS, emitting a delete or insert. Preferr...