Generate a Word Level Redline Between Two Clause Versions
Last updated: November 29, 2026
Quick Overview
Given the old and new text of a contract clause, produce a word-level redline that marks inserted and deleted words while keeping as many unchanged words as possible.
Harvey
November 29, 20260
0
0 solved
Given the old and new text of a contract clause, produce a word-level redline that marks inserted and deleted words while keeping as many unchanged words as possible.
Redlining is how lawyers negotiate, and Harvey's review and drafting features need to show exactly what a model or counterparty changed. The interviewer expects the LCS dynamic program, a correct backtrack that emits ordered edit operations, and a discussion of memory and readability trade-offs on long documents.
What the Interviewer Expects
- Reduce the problem to longest common subsequence over words
- Fill the DP table with a clear recurrence
- Backtrack into ordered keep, delete, insert operations
- Handle empty inputs and trailing runs
- Discuss O(nm) memory and alternatives such as Myers or Hirschberg
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 make the diff read more naturally, grouping deletes before inserts in each changed run?
- How would you diff a 200 page agreement without O(nm) memory?
- How do you detect a moved paragraph rather than a delete plus insert?
- Should punctuation and whitespace changes be shown, and how?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs are two strings; tokenize on whitespace. Output a list of (op, word) with op =, - or +, such that applying the ops to the old words yields the new words and the number of = is maximal...
High-Level Design
A minimal redline keeps a longest common subsequence of words, and everything else is a delete (old only) or insert (new only). Build a suffix table dp[i][j] = LCS length of a[i:] and b[j:], the...