Largest 3-Same-Digit Number in String - Problem
You are given a string num representing a large integer. An integer is good if it meets the following conditions:
- It is a substring of
numwith length 3. - It consists of only one unique digit.
Return the maximum good integer as a string or an empty string "" if no such integer exists.
Note:
- A substring is a contiguous sequence of characters within a string.
- There may be leading zeroes in
numor a good integer.
Input & Output
Example 1 — Multiple Good Integers
$
Input:
num = "6777133"
›
Output:
"777"
💡 Note:
The good integers are "777" and "333". Since "777" > "333", we return "777".
Example 2 — No Good Integer
$
Input:
num = "2300019"
›
Output:
"000"
💡 Note:
The only good integer is "000" (three consecutive zeros).
Example 3 — No Valid Triplets
$
Input:
num = "42352338"
›
Output:
""
💡 Note:
No substring of length 3 consists of only one unique digit.
Constraints
- 3 ≤ num.length ≤ 1000
- num only consists of digits.
Visualization
Tap to expand
Understanding the Visualization
1
Input
String containing digits: "6777133"
2
Process
Find all 3-character substrings with identical digits
3
Output
Return the lexicographically largest: "777"
Key Takeaway
🎯 Key Insight: Scan for consecutive identical triplets and track the lexicographically largest one
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code