Return the Greatest Repeated-Digit Triple in a Long Number
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Find contiguous length-three substrings of `num` containing only one repeated digit. Return the greatest such triple as a three-character string, or the empty string when none exists. Leading zeroes remain meaningful in the returned spelling.
```cpp
class Solution {
public:
string largestGoodInteger(string num);
};
```
### Examples
**Example 1:**
```text
Input: num = "2227771"
Output: "777"
Explanation: The triples "222" and "777" qualify, and "777" is greater.
```
**Example 2:**
```text
Input: num = "10002"
Output: "000"
Explanation: The triple "000" is valid and must retain all three zero characters.
```
### Constraints
- `3 <= num.length <= 1000`.
- num consists of decimal digits.
### Clarifying Questions
- Does a triple have to be contiguous? Yes; three equal digits at separate positions do not qualify.
- Is `"000"` different from no result? Yes. Return all three zero characters when it is the greatest qualifying triple.
- Can triples overlap? Yes; a run such as `"4444"` contains two occurrences of the same candidate.
```hint Check the boundary
Check the difference between a three-character result and an empty result.
```
Overview: Find the greatest three-character substring made of one repeated digit. Preserve leading zeroes and return an empty string when no triple qualifies.
Return the Greatest Repeated-Digit Triple in a Long Number
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
Find contiguous length-three substrings of num containing only one repeated digit. Return the greatest such triple as a three-character string, or the empty string when none exists. Leading zeroes remain meaningful in the returned spelling.
class Solution {
public:
string largestGoodInteger(string num);
};
Examples
Example 1:
Input: num = "2227771"
Output: "777"
Explanation: The triples "222" and "777" qualify, and "777" is greater.
Example 2:
Input: num = "10002"
Output: "000"
Explanation: The triple "000" is valid and must retain all three zero characters.
Constraints
3 <= num.length <= 1000
.
num consists of decimal digits.
Clarifying Questions Guidance
Does a triple have to be contiguous? Yes; three equal digits at separate positions do not qualify.
Is
"000"
different from no result? Yes. Return all three zero characters when it is the greatest qualifying triple.
Can triples overlap? Yes; a run such as
"4444"
contains two occurrences of the same candidate.