[
string
groupby
]
BinarySearch 0301 Longest Alliteration
Problem statement
https://binarysearch.com/problems/Longest-Alliteration/
Solution
Create array of the first letters, then use groupby.
Complexity
It is O(n)
for time and space, where n
is the total length of all words.
Code
class Solution:
def solve(self, words):
x = [w[0] for w in words]
ans = 0
for x, y in groupby(x):
ans = max(ans, len(list(y)))
return ans