LeetCode solutions

2847. Find Maximum Number of String Pairs

My accepted Python solution to LeetCode problem 2847, Find Maximum Number of String Pairs, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2025-12-31.

python
class Solution:
    def maximumNumberOfStringPairs(self, words: List[str]) -> int:
        count = 0
        seen = set()
        for word in words:
            if word[::-1] in seen:
                count += 1
            seen.add(word)
        return count

Source