FastPrepOne-Mismatch Consensus String
Problems/One-Mismatch Consensus String

One-Mismatch Consensus String

IMC Trading logoIMC Trading● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading online assessment. The task is about 95% the same as the report. The report left out the result when there is no answer and which valid answer to pick. This version returns an empty string, or the smallest valid string in dictionary order.

You are given N words in words. Every word contains exactly K lowercase English letters.

Return a string of length K that differs from every input word at no more than one position. Characters are compared at matching positions; rearranging letters is not allowed.

For this exercise, assume the lexicographically smallest valid string is returned when several exist. For this exercise, assume the answer is an empty string when no valid length-K string exists.

Function

consensusString(words: String[]) → String

Examples

Example 1

words = ["ab","ba"]return = "aa"

Both mixed strings aa and bb work; aa is smaller.

Example 2

words = ["abc","axc","aby"]return = "abc"

Differences occur at two distinct positions, forcing abc.

Example 3

words = ["abc","xyz"]return = ""

The words differ at three positions, so no answer can be within one of both.

Example 4

words = ["zzz","zzz"]return = "azz"

Changing the first character to a produces the smallest valid word.

Constraints

  • 2 <= N <= 10^5
  • 1 <= K <= 10^5
  • 2 <= N * K <= 10^6
  • Every word has length K and contains only lowercase English letters.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Find a String Within One Mismatch of AllBarclays · OA
  • Count Subarrays Matching a Comparison PatternTikTok · OA
  • Earliest Time to Schedule a MeetingMathWorks · OA
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Count One-Swap Number PairsCapital One · OA
  • Earliest Time to Schedule a MeetingMicrosoft · OA
  • Nested Recipe Blocks (Game Adaptation)Roblox · OA
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Maximum Equal Parts for PrefixesAmazon · OA
  • Best TV Show in a GenreAdyen · OA
See IMC Trading hiring insights
Saved
class Solution {
    public String consensusString(String[] words) {
        // Write your solution here.
    }
}
Checking account…