Stratup: was late for 5 min or so, due to my connection issue.
Warmup: interviewer introduced himself for 3 - 5 min.
Question: segment a search string with a bigram dictionary
input: "I like ice coffee." dict = ["ice coffee", "New York"]
output: ["I", "like", "ice coffee"]
我的解答:c++
1, split the search string into string vectors with space. confirmed with intervewer that the separator is only one space, no tabs, etc.
2, split each phrase in the bigram dictionary with space: unordered_map<string, unordered_set<string>>: key: the first word in the bigram, value: the list of the second word in the bigram. confirmed with interviewer that the length of the phrase is alway 2, no exceptions.
3, iterative over the preprocessed search vector with index:
for (int i = 0; i < search_vector.size(); )
when i < search_vector.size() - 1 and the i and i + 1 are both matched: push the bigram into the result vector, i += 2
else: push the ith word into the result vector, ++i
Till here, about 30 min passed.
asked about time complexity, given number of words in search string as N and number of phrases in the dictionary as M:
O(max{N, M})
follow up: N-gram match (N = any):
I gave an inaccurate answer as a tree node, but interviewer just mentioned not necessary to write the code out though I did. He was trying to confirm if I was about to use Trie, and I finally agreed.
Till here, about 40 min passed. the last 5 min was for questions.
Result: FAIURE
Feedback: "throughout the problem solving, you could have been more efficient in analyzing the issue. They would have liked to see you reach a solution faster by asking more questions at the outset to better understand the problem. " |