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
Coding & Algorithms
Software Engineer
Legora
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
longest common subsequence
dynamic programming
diff algorithms
tokenisation
tracked changes
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions