Rank Word-Translation Hints from Sentence Translations
Reported by candidates from Duolingo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Duolingo reported this one in April 2026, and it looks scarier than it is. Strip the story and it's a custom sort: for each word position, build a priority number per hint, then sort by (priority, string). If you've got an OA invite for Duolingo, expect this kind of spec-heavy problem where the trap is in the details, not the algorithm. Normalization rules and the tie-break are where people lose points. StealthCoder is the safety net if you blank on the live OA, but read the examples closely first and you probably won't need it.
The problem
An English sentence has one list of Spanish translation hints for each whitespace-delimited word occurrence. You are also given one bestTranslation and ordered alternativeTranslations. Every translation has the same number of whitespace-delimited tokens as the English sentence. For each word position, rank its hints in two stages: Lexicographically sort the hints. Assign sentence priority. A hint matching the normalized token at that position in bestTranslation has priority 0. Otherwise, its priority is j + 1 for the first alternative translation at index j whose token matches. A hint appearing in no sentence has priority alternativeTranslations.length + 1. Sort by priority, using the stage-one lexicographic order to break ties. Normalization lowercases a token and removes all leading and trailing ASCII punctuation characters.,!?;:. Punctuation inside a token is retained. Return the sorted hint list for every word position, preserving the original hint strings in the output. Function rankTranslationHints(sentence: String, hints: String[][], bestTranslation: String, alternativeTranslations: String[]) → String[][] Examples Example 1 sentence = "I eat apples." hints = [["me","yo"],["comer","como"],["fruta","manzana","manzanas"]] bestTranslation = "Yo como manzanas." alternativeTranslations = ["Me comer fruta.","Yo comer manzana!"] return = [["yo","me"],["como","comer"],["manzanas","fruta","manzana"]] Best-sentence tokens come first. For the final word, fruta appears in the first alternative and manzana in the second. Trailing punctuation is removed for matching. Example 2 sentence = "Hello world" hints = [["hola","buenas"],["tierra","mundo"]] bestTranslation = "¡Hola mundo!" alternativeTranslations = [] return = [["buenas","hola"],["mundo","tierra"]] The contract strips only the listed ASCII punctuation. The leading inverted exclamation mark in ¡Hola is retained, so neither first-position hint matches and lexical order decides that list. The trailing ASCII ! is stripped from mundo!. Constraints The English sentence contains between 1 and 100 whitespace-delimited tokens. hints.length equals the English token count. Each hint list contains between 1 and 50 non-empty strings. bestTranslation and every alternative contain the same number of whitespace-delimited tokens as the English sentence. 0 <= alternativeTranslations.length <= 20. Lexicographic comparison uses the original string values.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that the two-stage sort collapses into one comparator. Sort by priority first, then by original string. Lexicographic order as a tiebreak is the same as stage one, so you don't need two passes. For each position i, normalize the token from bestTranslation and each alternative at i. Build a map from normalized token to the lowest priority: 0 for best, j+1 for alternative j, using first match only. Hints not in the map get alternatives.length + 1. Pitfalls: normalizing the hints themselves (don't, the spec compares hints as given against normalized tokens, though you should check whether hints are lowercase in your cases), stripping inner punctuation (don't), and stripping non-ASCII marks like the inverted exclamation mark in Example 2 (don't). Output the original hint strings. Complexity is tiny at 100 positions and 50 hints. StealthCoder is the hedge if the comparator logic slips under time pressure.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Rank Word-Translation Hints from Sentence Translations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Duolingo's OA.
Duolingo reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rank Word-Translation Hints from Sentence Translations FAQ
How hard is the Duolingo translation hints problem really?+
Easy to medium. The algorithm is a sort with a custom key. The difficulty is reading the spec carefully: normalization, first-match priority, and the default priority for hints that appear nowhere. Most failures come from small spec misreads, not from the algorithm.
What's the trick to ranking the hints?+
Use one comparator: priority first, original string second. Per position, map each normalized translation token to its best priority (0 for best, j+1 for alternative j, first match wins). Anything unmatched gets alternatives.length + 1. Then sort with that key.
How should I normalize tokens?+
Lowercase the token, then strip only leading and trailing ASCII punctuation from the set,. ! ? ; and :. Leave inner punctuation alone. Non-ASCII characters like the inverted exclamation mark stay put, which is exactly what Example 2 tests.
Is this sorting pattern still asked in 2026?+
Custom-comparator sorting with a spec-heavy setup was reported at Duolingo in April 2026. It's a common OA shape because it tests careful reading and clean code over clever algorithms. Expect more of these with string handling rules.
How do I prepare in 48 hours?+
Practice writing custom sort keys in your language, such as tuples or comparator functions. Then hand-trace both examples against your code, especially the ones with punctuation and empty alternatives. Test edge cases: zero alternatives, duplicate matches across alternatives, and a hint list with a single entry.