Google Onsite Coding Interview question
Anonymous User
2106

I was asked this question in my Google onsite.
Basically leetcode 720 - https://leetcode.com/problems/longest-word-in-dictionary/ but with the caveat that words can be added in any order.
Example input/output:

starting_character = "a"
dictionary = ["a", "an", "ant", "want", "ba", "bat"]

Output: "want"
Explanation: "a" -> "an" -> "ant" -> "want"

starting_character = "s"
dictionary = ["t", "ta", "w", "star", "sta", "stars", "ba", "bat"]

Output: "stars"
Explanation: "t" -> "ta" -> "sta" -> "star" -> "stars"

I could only do the brute force approach. Any suggestions on how to do this?

Comments (12)