Find the largest 3-character substring made of the same digit.
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
numcontaining only digit characters0-9. - Consider all contiguous substrings of length
3innum.
Output Format
- Return the largest 3-character substring where all characters are the same.
- If no such substring exists, return
"".
Constraints
1 <= num.lengthnumcontains only digits0-9.- The task is to inspect contiguous length-3 substrings only.
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.