Anchor AI Suggested Edits to a Document That Has Changed

Last updated: November 29, 2026

Quick Overview

An LLM proposes edits as (quote, prefix, suffix, replacement), but the lawyer may have edited the document since. Write a function that locates each quote in the current text using its surrounding context, rejects missing or ambiguous anchors, rejects edits that overlap an already accepted edit, and applies the rest.

Legora
Software Engineering Fundamentals
Frontend Engineer
Legora
November 29, 2026
Frontend Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


An LLM proposes edits as (quote, prefix, suffix, replacement), but the lawyer may have edited the document since. Write a function that locates each quote in the current text using its surrounding context, rejects missing or ambiguous anchors, rejects edits that overlap an already accepted edit, and applies the rest.

Legora's Word add-in drafts and redlines inside a live document, so suggestions must land on the right text even after the user keeps typing. The interviewer checks robust anchoring (not character offsets), deterministic conflict handling, and applying edits without shifting later positions.

What the Interviewer Expects
  • Explains why raw character offsets go stale and uses text plus context anchors
  • Scores every occurrence of the quote by prefix and suffix agreement
  • Refuses ambiguous ties instead of guessing which clause to change
  • Detects overlapping edits and applies a clear precedence rule
  • Applies edits from right to left so earlier offsets stay valid
  • Reports a per-edit status the UI can show
Key Topics to Cover
text anchoring
conflict detection
string algorithms
Word add-in
idempotent edits
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you tolerate small changes inside the quote itself, such as a fixed typo?
  • How does this map onto Office.js ranges and tracked changes rather than a plain string?
  • What if two collaborators accept conflicting suggestions at the same time?
  • How would you test the anchoring on real redlined agreements?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Each edit carries the exact quote it targets, up to 40 characters of prefix and suffix seen when it was generated, and a replacement. The document may have changed. For each edit return `appli...

High-Level Design

Locate, then resolve, then apply. Locate: find all occurrences of the quote; score each by length of common suffix between the stored prefix and the text before it, plus common prefix of the store...


Submit Your Answer
Markdown supported

Related Questions