Sitemap
Javascript by doing

Learn javascript by 10 min code example

Member-only story

🏆 Meta Hacker Cup 2022 — Round 3: Second Mistake

4 min readAug 21, 2026

--

Difficulty: Medium
Category: String Matching & Combinatorics
Original Problem

Problem Summary

You have a vocabulary of N distinct words, each of length L, using only the letters {m, e, t, a}. Your friend wrote Q misspelled words, also of length L using the same alphabet.

For each misspelled word, count how many vocabulary words differ from it at exactly 2 positions. Sum all counts across all Q queries.

Example:

  • Vocabulary: [“meta”, “meet”, “mete”]
  • Query word: “mate”
  • “meta”: differs at positions 1 (a vs e) and 3 (t vs e) → 2 differences âś“
  • “meet”: differs at positions 1 (a vs e) → 1 difference âś—
  • “mete”: differs at positions 1 (a vs e), 2 (t vs e), 3 (e vs t) → 3 differences âś—
  • Count: 1

Understanding the Problem

Hamming Distance

The “differ at exactly 2 positions” concept is Hamming distance = 2. The Hamming distance between two strings is the number of positions where their characters differ.

Brute Force Approach

--

--

Riccardo Canella @ricanella92 Love #basket, #bike and #HIMYM since my childhood. #Fullstack #Javascript addicted - https://canellariccardo.it