3527. Find the Most Common Response
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 74% Topics: Array, Hash Table, String, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n * l)
# Space: O(n * l)
import collections
# hash table, freq table
class Solution(object):
def findCommonResponse(self, responses):
"""
:type responses: List[List[str]]
:rtype: str
"""
cnt = collections.defaultdict(int)
for r in responses:
for x in set(r):
cnt[x] += 1
return min((-c, x) for x, c in cnt.iteritems())[1]
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions