Skip to content
LC-2744 Easy LeetCode

2744. Find Maximum Number of String Pairs

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 81% Topics: Array, Hash Table, String, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

import collections


# freq table
class Solution(object):
    def maximumNumberOfStringPairs(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        result = 0
        cnt = collections.Counter()
        for w in words:
            result += cnt[w[::-1]]
            cnt[w] += 1
        return result

Solution from kamyu104/LeetCode-Solutions · MIT