Beginner Code Challenge: Find the Missing Letter

September 02, 2025

Beginner Code Challenge: Find the Missing Letter

The challenge

From a list of words, find the letter(s) of the English alphabet that never appear in any of the words. Example dataset: the names of the U.S. states. Which letter never shows up in any state name?

Spoiler: the answer is "q".

Your first pass (works!)

Here's a straightforward way to approach it: scan through each word and keep track of the letters you encounter. At the end, whatever letters you never saw are your result.

const usStates = [
  "Alabama",
  "Alaska",
  "Arizona",
  "Arkansas",
  "California",
  "Colorado",
  "Connecticut",
  "Delaware",
  "Florida",
  "Georgia",
  "Hawaii",
  "Idaho",
  "Illinois",
  "Indiana",
  "Iowa",
  "Kansas",
  "Kentucky",
  "Louisiana",
  "Maine",
  "Maryland",
  "Massachusetts",
  "Michigan",
  "Minnesota",
  "Mississippi",
  "Missouri",
  "Montana",
  "Nebraska",
  "Nevada",
  "New Hampshire",
  "New Jersey",
  "New Mexico",
  "New York",
  "North Carolina",
  "North Dakota",
  "Ohio",
  "Oklahoma",
  "Oregon",
  "Pennsylvania",
  "Rhode Island",
  "South Carolina",
  "South Dakota",
  "Tennessee",
  "Texas",
  "Utah",
  "Vermont",
  "Virginia",
  "Washington",
  "West Virginia",
  "Wisconsin",
  "Wyoming",
];

const alphabet = [
  "a",
  "b",
  "c",
  "d",
  "e",
  "f",
  "g",
  "h",
  "i",
  "j",
  "k",
  "l",
  "m",
  "n",
  "o",
  "p",
  "q",
  "r",
  "s",
  "t",
  "u",
  "v",
  "w",
  "x",
  "y",
  "z",
];

let misses = [];

for (let i = 0; i < usStates.length; i++) {
  const state = usStates[i].toLowerCase();
  for (let j = 0; j < alphabet.length; j++) {
    if (state.includes(alphabet[j])) {
      misses.push(alphabet[j]);
      continue;
    }
  }
}

console.log(alphabet.filter((letter) => !misses.includes(letter))); // ["q"]

This version works because you're collecting every letter that appears at least once, then filtering the alphabet to find what never appeared. It does extra work (like pushing duplicates), but the final filter handles it.

A cleaner Set-based solution

We can improve two things:

  • Avoid duplicates: use a "Set" to record seen letters.
  • Scan characters directly: we don't need to check each alphabet letter against each word - we just record what we see as we iterate.
const usStates = [
  "Alabama",
  "Alaska",
  "Arizona",
  "Arkansas",
  "California",
  "Colorado",
  "Connecticut",
  "Delaware",
  "Florida",
  "Georgia",
  "Hawaii",
  "Idaho",
  "Illinois",
  "Indiana",
  "Iowa",
  "Kansas",
  "Kentucky",
  "Louisiana",
  "Maine",
  "Maryland",
  "Massachusetts",
  "Michigan",
  "Minnesota",
  "Mississippi",
  "Missouri",
  "Montana",
  "Nebraska",
  "Nevada",
  "New Hampshire",
  "New Jersey",
  "New Mexico",
  "New York",
  "North Carolina",
  "North Dakota",
  "Ohio",
  "Oklahoma",
  "Oregon",
  "Pennsylvania",
  "Rhode Island",
  "South Carolina",
  "South Dakota",
  "Tennessee",
  "Texas",
  "Utah",
  "Vermont",
  "Virginia",
  "Washington",
  "West Virginia",
  "Wisconsin",
  "Wyoming",
];

const alphabet = [..."abcdefghijklmnopqrstuvwxyz"]; // ["a", "b", ..., "z"]

const seen = new Set();
for (const state of usStates) {
  for (const ch of state.toLowerCase()) {
    if (ch >= "a" && ch <= "z") seen.add(ch);
  }
}

const missing = alphabet.filter((ch) => !seen.has(ch));
console.log(missing); // ["q"]

Why this is better

  • Simplicity: one pass to gather letters, one pass to compare to the alphabet.
  • Performance: no repeated "includes" checks per letter per word.
  • Robustness: safely ignores spaces, hyphens, and punctuation.

Try it with your own lists

Swap in any list of words - countries, Pokémon, your friends' names and see which letters are missing. For non-English alphabets or accented characters, adapt the "alphabet" and the character-filtering logic to fit your dataset.

How would you approach this problem? Do you have any other solutions? Anyways, Happy puzzling!