LeetCode solutions

3736. Find Valid Pair of Adjacent Digits in String

My accepted Python solution to LeetCode problem 3736, Find Valid Pair of Adjacent Digits in String, running in 7ms.

  • Difficulty: Easy
  • Python
  • Runtime 7ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 17.4MB, accepted 2026-01-01.

python
class Solution:
    def findValidPair(self, s: str) -> str:
        from collections import Counter
        freq = Counter(s)
        for i in range(len(s) - 1):
            a, b = s[i], s[i + 1]
            if a != b and freq[a] == int(a) and freq[b] == int(b):
                return a + b
        return ""

Source