I was recently asked this in one of my technical coding interview and I am really struggling to find a solution/similar problem on leetcode and elsewhere. If any of you know a good solution or can point me to a link where a similar problem/solution exists, please do so. Appreciate the help I can receive on this forum!
Here's the question:
When you’re typing too fast you might press the wrong key. For example if you want to press G you might press its neighbors T, F, B or H (all with distance 1 from G) or even worse by pressing further letters like R (at distance 2) or Z(at distance 5).
The keyboard layout looks like this:
q w e r t y u i o p
a s d f g h j k l
z x c v b n m
Given a word as search_term, search among all entries in the database and find every occurrence of that word with the distance of at most maximum_distance
Example Input:
{ "maximum_distance": 3, "search_term": “taj”},
Example Database:
[
"The King David Jerusalem Hotel, Jerusalem",
"Burj Al Arab Jumeirah, Dubai",
"The Plaza, New York City",
"Fairmont Le Chateau Frontenac, Quebec City",
"Old Faithful Inn, Yellowstone National Park",
"Grand Hotel Europe, St. Petersburg",
"Disney's Contemporary Resort, Florida",
"The Beverly Hills Hotel, Beverly Hills",
"Taj Mahal, Mumbai"
]
Example output:
Found: rab, Distance: 3, Hotel: Burj Al Arab Jumeirah, Dubai
Found: rah, Distance: 1, Hotel: Burj Al Arab Jumeirah, Dubai
Found: Fai, Distance: 2, Hotel: Fairmont Le Chateau Frontenac, Quebec City
Found: ten, Distance: 3, Hotel: Fairmont Le Chateau Frontenac, Quebec City
Found: Fai, Distance: 2, Hotel: Old Faithful Inn, Yellowstone National Park
Found: Taj, Distance: 0, Hotel: Taj Mahal, Mumbai