i recently had the opportunity to interview at google for their web solutions engineer position
yoe-2
source-recruiter reached out to me on linkedin
Given a list of words, write a function such that it takes a character-by-character stream and return words from the provided list as they are found in the stream.
The function should return either null or '' if the call cannot produce a word yet.
When a word can be made, the characters should be removed from the stream and the word should be returned.
MyWordProducer producer = new MyWordProducer(Set.of("foo", "bar", "fan"));
producer.produceWord('a'); returns null
producer.produceWord('b'); returns null
producer.produceWord('c'); returns null
producer.produceWord('f'); returns null
producer.produceWord('n'); returns null
producer.produceWord('d'); returns null
producer.produceWord('r'); returns "bar"
producer.produceWord('o'); returns null
producer.produceWord('r'); returns null
producer.produceWord('o'); returns "foo"
producer.produceWord('a'); returns null
can someone give ways to solve this question, i tried it using hashmaps but did not get the proper solution out of it