You are given a non-negative integer n. Your task is to return the length of the longest run of identical consecutive digits in the number.
A run is a sequence of two or more identical digits appearing consecutively. If no digit repeats consecutively, the longest run has a length of 1.
Input: n = 1112233
Output: 3
Explanation: The digit 1 appears three times consecutively, forming the longest run of length 3.
Input: n = 4455566
Output: 3
Explanation: The digit 5 appears three times consecutively, forming the longest run of length 3.
Input: n = 1234
Output: 1
Explanation: No digit repeats consecutively, so the longest run has a length of 1.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1112233
3
4455566
3