Abbreviations Unique?

Published by Deep Xavier in

You are given two inputs:

  1. An array of abbreviations.
  2. An array of words.

Write a function that returns true if each abbreviation uniquely identifies a word, and false otherwise.

Examples

uniquely(["ho", "h", "ha"], ["house", "hope", "happy"]) ➞ false
// "ho" and "h" are ambiguous and can identify either "house" or "hope"

uniquely(["x", "l", "t"], ["xavier", "loves", "tesh"]) ➞ true

uniquely(["s", "t", "v"], ["stamina", "television", "vindaloo"]) ➞ true

uniquely(["bi", "ba", "bat"], ["big", "bard", "battery"]) ➞ false

uniquely(["mo", "ma", "me"], ["moment", "many", "mean"]) ➞ true

Notes

Abbreviations will be a substring from [0, n] from the original string.

Watch a quick demo on how Edabit works.