[Java/Python 3] 1 liners and a follow-up.
\n\njava\n    public int prefixCount(String[] words, String pref) {\n        return (int)Stream.of(words).filter(w -> w.startsWith(pref)).count();\n    }\n\npyt
\n\n```java\n    public int prefixCount(String[] words, String pref) {\n        return (int)Stream.of(words).filter(w -> w.startsWith(pref)).count();\n    }\n```\n```python\n    def prefixCount(self, words: List[str], pref: str) -> int:\n        return sum(w.startswith(pref) for w in words)\n```\n\n----\n\n**Follow-up:**\n\n*Q*: A followup question from Google: what if the words are sorted lexicographically? -- credit to **@blackspinner**\n*A*: We can use binary search twice to locate the lower and upper bounds of the words that have the same prefix. Therefore, the time cost is O(klogn). e.g., \nAssume `perf = "abcd"`, we can search `"abcd"` and `"abce"` respectively.\n\n\n
[]