Stack Bash - Master data structures and algorithms

One edit away

Hard
Let's say you're given two strings a and b.
Write a function that determines if the strings are one or zero edits away from eachother.
Consider a single edit as one of the following:
  1. An inserted character
  2. A replaced character
  3. A removed character
For example, given the two strings:
a = "car"
b = "bar"
Your function should return True, since there is only one character replaced.
Another example:
a = 'baby'
b = 'babies'
Your function should return False since a and b are more than 1 edit away from eachother.

Try it first

Solution

6 Essential Strings Coding Interview Problems

Master Strings by trying the coding challenges below.
  1. 1.Reverse StringEasy
  2. 2.AnagramEasy
  3. 3.Reverse wordsMedium
  4. 4.String matchMedium
  5. 5.CompressionMedium
  6. 6.One edit awayHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.