Amazon | Phone Screen | Tokens in String
Anonymous User
1571

You are given an input String "Word" and a input List "Tokens". Return true or false if the Word can be constructed with the tokens given.

Restraints: Case Sensitivity matters, token length can be 1 to 50. Word can be null or "". The word is not sorted.

Ex: String word = "BBAACC" List tokens = ["AA","BB",CC",DD"] --> Output = true
Ex: String word = "AABBcD" List tokens = ["AA","BB",CC",DD"] --> Output = false "c" is not a token
Ex: String word = "AABBCC" List tokens = ["AA","BB","CCCC"] --> Output = false "CC" is not a token.

Is there a similar leetcode question to this? I looked and couldn't really find anything. I could only really come up with a brute force solution by looping through word.length and then looping through each token. I was rejected.

Comments (7)