Earlier Tail Matches
This function is good practice for finding a small pattern inside a string. Write a function last2 that takes a string s, looks at its last two characters, and counts how many times the same pair appeared earlier in the string. Do not count the final occurrence itself, because it is the ending you are comparing against.
Примеры
Ввод
"hixxhi"Вывод
1Ввод
"xaxxaxaxx"Вывод
1Ввод
"axxxaxaxx"Вывод
2Нужно реализовать
def last2(s: str) -> int:
Теги
stringssliding-window
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięTests12
Visible tests
Ukryty test 7
Ukryty test 8
Ukryty test 9
Ukryty test 10
Ukryty test 11
Ukryty test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid