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

0

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
2D dynamic programming
longest common subsequence
diff algorithms
backtracking
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported