Skip to main content
Back to problems
Leetcode
Easy
Strings
Arrays
Largest 3 Same Digit Number In String

Find the largest 3-character substring made of the same digit.

Acceptance 0%
Problem Statement

Given a string of digits, look for every substring of length 3. Return the largest numeric substring that consists of the same digit repeated three times, such as 777 or 000. If no such substring exists, return an empty string.

The answer should be the numerically largest valid substring, not the first one encountered.

Input Format

  • A string num containing only digit characters 0-9.
  • Consider all contiguous substrings of length 3 in num.

Output Format

  • Return the largest 3-character substring where all characters are the same.
  • If no such substring exists, return "".

Constraints

  • 1 <= num.length
  • num contains only digits 0-9.
  • The task is to inspect contiguous length-3 substrings only.
Examples
Sample cases returned by the problem API.

Example 1

Input

"6777133339"

Output

"777"

Explanation

The substrings 777 and 333 are valid, and 777 is numerically larger.

Example 2

Input

"2300019"

Output

"000"

Explanation

The substring 000 is the only length-3 substring with all equal digits.

Show 1 more example

Example 3

Input

"42352338"

Output

""

Explanation

No length-3 substring has all three digits the same.

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.