File: largest-3-same-digit-number-in-string/solution.py

Date: 2026-06-06

Time: 17:13

largest-3-same-digit-number-in-string/solution.py

Purpose

This file solves LeetCode 2264: Largest 3-Same-Digit Number in String. It finds the lexicographically largest substring of length 3 where all three characters are the same digit (a "good integer"). The file follows the repo's standard pattern: one Solution class per problem directory.

Key Components

Solution.splitandminimize — The method name is a misnomer (likely a copy-paste artifact from another problem). It actually implements largestGoodInteger from the LeetCode problem. The contract:

Flow

1. Initialize result to "" (the empty string acts as a sentinel — it compares less than any 3-digit string lexicographically).

2. Slide a window of size 3 across num via range(len(num) - 2).

3. At each position i, check if all three characters are equal: num[i] == num[i+1] == num[i+2].

4. If so, extract the candidate num[i:i+3] and keep it if it's lexicographically greater than the current result.

5. Return the best match, or "" if none was found.

Patterns

Dependencies

Invariants

Error Handling

None. The method assumes valid input per the LeetCode constraint (a string of digits with length >= 3). If given a string shorter than 3, range(len(num) - 2) produces an empty range and the method silently returns "".

Notable Issue

The method is named splitandminimize, which is the name of a different LeetCode problem. This is a bug in the code generation pipeline — the logic is correct for "Largest 3-Same-Digit Number in String", but the method name doesn't match.

Topics to Explore

Beliefs