Rank Common Translation Mistakes
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 September 2022, and it looks like a sorting problem until you read it twice. Really it's a counting problem with a sort bolted on the end. You get a grid of translated words, find the winning word at each column, and tally everything that lost. If your OA is in a day or two, this is a clean one to nail. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic below is short enough to carry in your head.
The problem
Learners submit translations of the same sentence. You are given submissions, where every row contains the translated words in their sentence positions. For each position independently, find its greatest word frequency. Every word tied for that greatest frequency is considered correct at that position. Every occurrence of any other word at that position is a mistake. Aggregate the number of mistaken occurrences for each word across all positions and submissions. Return each distinct mistake word exactly once, ordered by decreasing mistake frequency. When two mistake words have the same frequency, order them alphabetically. Function countingMistakes(submissions: String[][]) → String[] Examples Example 1 submissions = [["your","bear","drinks","beer"],["your","bear","eats","beer"],["the","bear","drinks","beer"]] return = ["eats","the"] At position 0, your is modal and the is one mistake. At position 2, drinks is modal and eats is one mistake. Both mistake frequencies are 1, so alphabetical order places eats before the. Example 2 submissions = [["your","bear","drinks","beer"],["your","bear","eats","beer"],["the","bear","drinks","beer"],["your","bear","the","beer"]] return = ["the","eats"] The word the is mistaken once at position 0 and once at position 2, for a total of 2. The word eats is mistaken once, so the appears first. Constraints 1 <= submissions.length <= 1000. 1 <= submissions[i].length <= 100, and every submission has the same length. Every word has length from 1 through 30. Words contain only lowercase letters a through z and digits 0 through 9. The same word may occur more than once in one submission.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Here's the reduction. Go column by column. Build a frequency map for that position, find the max count, and mark every word hitting that max as correct. Every other word at that position adds its count to a global mistake map. Don't add one per word, add its full occurrence count, since each occurrence is a mistake. Then sort the map keys by mistake count descending, ties alphabetical. The classic pitfall is treating a single modal word as the winner. Ties at the max are all correct, so Example 1 can't punish them. Another trap is counting a word that's correct in one column but wrong in another. It belongs in the output if its total mistakes are above zero. Complexity is O(n*m) for counting plus a sort over distinct mistake words. If you freeze during the live OA, StealthCoder is the hedge that gets you to the same code.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Rank Common Translation Mistakes 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 Common Translation Mistakes FAQ
What's the trick in Rank Common Translation Mistakes?+
Treat each position independently. Count word frequencies per column, find the max, and every word tied at the max is correct. All other occurrences go into one global mistake counter. Then sort by count descending and word ascending. That's the whole problem.
How do I handle ties at the top of a column?+
Every word tied for the greatest frequency counts as correct at that position. Don't pick one winner. Collect all words whose count equals the max and skip them when adding to the mistake map. Missing this gives wrong answers on tie-heavy inputs.
Does a word with zero mistakes appear in the output?+
No. Only words with at least one mistaken occurrence are returned, each exactly once. A word that's always correct never enters the mistake map, so it never shows up. Build the map only from non-modal occurrences and you're fine.
How hard is this really for an OA?+
Easy to medium. No fancy data structures. It's hash maps plus a custom comparator. With up to 1000 submissions and 100 positions, the straightforward approach runs fast. Most of the risk is misreading the tie rule or the sort order.
How do I prepare in 48 hours?+
Write this solution once from scratch. Practice the multi-key sort in your language: negative count first, then the word. Test it on both examples, especially Example 2 where 'the' beats 'eats'. Then rehearse one or two other frequency-plus-sort problems.