Ctrl K

Triples and One Pair

Easy
The digit string digits must be cut into consecutive pieces so that: - every piece consists of one repeated digit; - exactly one piece has length 2, and all the others have length 3. Return True if such a cut exists, and False otherwise.
Example 1
digits="55566677" → True

Cut it as "555", "666", "77": two triples and one pair.

Example 2
digits="444888" → False

Only triples come out, but there must be exactly one pair.

Example 3
digits="1122333" → False

"11" and "22" make two pairs, but only one is allowed.

Constraints
  • 1 ≤ len(digits) ≤ 1000
  • digits consists of digits only
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
digits="55566677"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 17 tests on the server, hidden ones included.