Problem · Trie
MediumUberFULLTIMEOA
See Uber hiring insights

Problem statement

Please check out the second source image below for more details :)

Once upon a time in a land of letters and words, there was a curious puzzle that needed solving. The puzzle involved an array of words, each holding a special place in a magical list. The task was to find pairs of words that had a special relationship. Specifically, these pairs were defined by either the two words being exactly the same or one word starting with the other.

Function

wordPairs(magics: String[]) → int

Examples

Example 1

magics = ["back","backdoor", "gammon", "backgammon", "comeback", "come", "door"]return = 3
The relevant pairs are: words[0] = "back" and words[1] = "backdoor" words[0] = "back" and words[3] = "backgommon" words[4] = "comeback" and words[5] = "come"

Example 2

magics = ["abc","a", "a", "b", "ab", "ac"]return = 8
N/A for now

More Uber problems

drafts saved locally
public int wordPairs(String[] magics) {
  // write your code here
}
magics["back","backdoor", "gammon", "backgammon", "comeback", "come", "door"]
expected3
checking account