#3438
Find Valid Pair of Adjacent Digits in String
easy · 60.6% accepted · 78 likes · top 59%
hash table · string · counting
Description
You are given a string s consisting only of digits. A valid pair is defined as two adjacent digits in s such that:
- The first digit is not equal to the second.
- Each digit in the pair appears in s exactly as many times as its numeric value.
Return the first valid pair found in the string s when traversing from left to right. If no valid pair exists, return an empty string.
Solution