C++20 sections · 1024 units
Open in Course

Football - Implementation

Working solution

I use a counter to track consecutive identical characters:

function checkFootball(s)
count := 1
for i from 1 to length of s - 1
if s[i] = s[i - 1] then
 count := count + 1
 if count >= 7 then
 return "YES"
 else
 count := 1
 return "NO"
``` The loop compares each character to its predecessor. When you find a match, you increase the count. When you find a difference, you reset. Consecutive counting requires tracking when the current value matches the previous one. Reset the streak counter when they differ, increment when they match. The maximum updates whenever the streak exceeds it.