FastPrepRank Word-Translation Hints from Sentence Translations
Problems/Rank Word-Translation Hints from Sentence Translations

Rank Word-Translation Hints from Sentence Translations

Duolingo logoDuolingo● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report requires sorting words alphabetically first. Then it asks for priority from a best sentence and its alternatives, with punctuation handled. The report does not give the exact record format or the tie rules. We spelled those out and kept both reported steps.

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:

  1. Lexicographically sort the hints.
  2. 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.

More Duolingo interview questions

  • Longest Decreasing Matrix Path with Limited RelaxationsONSITE INTERVIEW · Seen Nov 2025
  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026

Similar questions at other companies

  • Parse and Order Structured LogsCoinbase · ONSITE INTERVIEWCoinbase interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Duolingo SWE Interview Questions: 3 Experiences

Duolingo interview experiences

  • Duolingo interviews · November 2026
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public String[][] rankTranslationHints(String sentence, String[][] hints, String bestTranslation, String[] alternativeTranslations) {
        // write your code here
    }
}
Checking account…