Closest Accepted Sentence in a Translation Template

Last updated: November 29, 2026

Quick Overview

Accepted translations are stored compactly as a sequence of slots, where each slot lists alternative word sequences and an empty alternative makes the slot optional. Given a learner's answer, return the minimum word-level edit distance between the answer and any sentence the template can generate, without expanding all sentences.

Duolingo
Coding & Algorithms
Software Engineer
Duolingo
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Accepted translations are stored compactly as a sequence of slots, where each slot lists alternative word sequences and an empty alternative makes the slot optional. Given a learner's answer, return the minimum word-level edit distance between the answer and any sentence the template can generate, without expanding all sentences.

A single Duolingo sentence can have thousands of correct translations once you combine contractions, synonyms and optional words, so expanding them all is wasteful. This onsite problem checks whether the candidate can fold the alternatives into an edit-distance dynamic program and explain why the state stays small.

What the Interviewer Expects
  • Notices that expanding the template is exponential in the number of slots
  • Defines DP state as the best cost of matching the first s slots against the first j answer words
  • Handles each alternative with an inner edit-distance pass seeded by the previous slot's row
  • Treats an empty alternative as an optional slot correctly
  • States complexity in terms of total alternative words times answer length
Key Topics to Cover
Dynamic programming
Edit distance
Grammar and lattice matching
Complexity analysis
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 recover which alternative the learner was closest to, to show a correction?
  • How would you weight substitutions of near-synonyms lower than unrelated words?
  • What changes if the template is a general graph with shared suffixes rather than a slot sequence?
  • How would you combine this with per-word typo tolerance?
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

Template: list of slots, each a list of alternatives, each a tuple of lowercase words; () means the slot can be skipped. Answer: a string. Operations are word insertion, deletion and substitution at...

High-Level Design

Let dp[j] be the cheapest way to match all slots processed so far against words[:j]. For the next slot, each alternative is matched against a suffix of the answer with standard edit distance, but ...


Submit Your Answer
Markdown supported

Related Questions