> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Largest 3-Same-Digit Number in String

> Tested Python solution for LeetCode 2264 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 2264, [Easy](/catalog/easy). Topics: [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/largest-3-same-digit-number-in-string/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 2264   # by problem number
lcpy gen -s largest_3_same_digit_number_in_string   # by problem name
```

## 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 `num` with 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 `num` or a good integer.

### Examples

```
Input: num = "6777133339"
Output: "777"
Explanation: There are two distinct good integers: "777" and "333". "777" is the largest, so we return "777".
```

```
Input: num = "2300019"
Output: "000"
Explanation: "000" is the only good integer.
```

```
Input: num = "42352338"
Output: ""
Explanation: No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
```

### Constraints

* 3 \<= num.length \<= 1000
* num only consists of digits.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_3_same_digit_number_in_string/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_3_same_digit_number_in_string/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def largest_good_integer(self, num: str) -> str:
        best = ""
        for i in range(len(num) - 2):
            if num[i] == num[i + 1] == num[i + 2] and num[i] * 3 > best:
                best = num[i] * 3
        return best
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.