Skip to main content
Back to problems
Leetcode
Medium
Strings
Arrays
Hash Maps
Find Valid Pair Of Adjacent Digits In String

Find the first adjacent pair of digits in a string that satisfies a validity rule based on digit frequencies.

Acceptance 0%
Problem Statement

Given a string consisting only of digits, examine each pair of adjacent characters from left to right and return the first pair that is considered valid according to the problem's rule. If no adjacent pair satisfies the condition, return an empty result or a sentinel value as specified by the platform version.

A typical validity rule for this kind of problem is that the two digits must be different and each digit must appear in the string exactly as many times as its numeric value. The goal is to identify the earliest adjacent pair that meets the rule after counting digit frequencies across the whole string.

Input Format

  • A string s containing only numeric characters.
  • The string length is at least 2.

Interpret the exact validity rule using the platform statement; the most likely rule is based on global digit frequencies and adjacent characters.

Output Format

  • Return the first valid adjacent pair as a 2-character string if one exists.
  • Otherwise, return an empty string or the platform's no-answer sentinel.

Constraints

  • 2 <= s.length
  • s contains only characters '0' to '9'
  • Scan adjacent pairs from left to right.
  • Use the platform's exact validity condition for the pair.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "1210"

Output

"21"

Explanation

Digit frequencies are: 1 -> 2 times, 2 -> 1 time, 0 -> 1 time. The adjacent pair "12" is not valid, but "21" is the first pair where each digit appears in the string exactly as many times as its value.

Example 2

Input

s = "123"

Output

""

Explanation

No adjacent pair satisfies the validity rule.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.