|
|
|
|
|
by SomeStupidPoint
3464 days ago
|
|
You can't have finite counters per word, else you can't disambiguate between counter length of a single word then the pattern I described and just the pattern I described, despite the fact it impacts the answer. Your solution is incorrect because it fails to handle arbitrary length streams as specified -- as do the other glib answers. My point was the specification didn't seem to align with the intended problem, and that interviewers tend to make such mistakes on the description, and then get mad when you ask them to clarify if we're talking practice or theory. Similarly, you don't account for arbitrary proper nouns, which could theoretically be unboundedly introduced to an arbitrary sized English corpus. I guess you can debate which of these are "English" (itself a proper noun!), but interviewers often treat you as dumb if you don't divine their intent in such underspecified situations. |
|
You only need one counter per word.
a quick sketch of the basic algorithm is:
This algorithm is O(N) space where N is the number of distinct items, as I mentioned previously.