Practice Find the Longest Semi-Repetitive Substring
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a digit string s that consists of digits from 0 to 9. A string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, "0010", "002020", "0123", "2002", and "54944" are semi-repetitive while the following are not: "00101022" (adjacent same digit pairs are 00 and 22), and "1101234883" (adjacent same digit pairs are 11 and 88). Return the length of the longest semi-repetitive substring of s.
Source: Find the Longest Semi-Repetitive Substring on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "52233"
4
# Example 2
s = "5494"
4
# Example 3
s = "1111111"
2
Constraints
Related LeetCode Problems
Practice more problems similar to Find the Longest Semi-Repetitive Substring.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.