Skip to content

Instantly share code, notes, and snippets.

@FremyCompany
FremyCompany / readme.md
Last active June 15, 2022 06:26 — forked from DigiTec/readme.md

Spoiler pages for the FindNearbyWords challenge

The goal of the exercise is to find an efficient way to take an existing word and lookup all words in a dictionary that differ from the original by only a single character. This is the kernel function for larger algorithmic problems like the Word Ladder, where you try to find the shortest route between two words, by changing one character at a time, and where each intermediate step must be in an intial dictionary of words.

Bruce Force

The simplest algorithm possible will take the input word and then compare it against every word in the dictionary, character by character, and count the differences. If the character differences between the word are just 1, then we add it to our list, otherwise we reject it. JavaScript has the Array.filter method which does precisely what we want and we just supply a function which returns true or false depending on if our criterion are met.

It is possible to optimize differsByOne further to get more benefits, but given t