Matching Tail Pair

This is good practice for finding a short substring inside a larger string. Write a function last2 that takes the last two characters of the string s and counts how many times the same pair appears 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:

Теги

strings
PostgreSQLv16

Tady se objeví výsledek běhu kódu

Visible tests
1
Input
"hixxhi"
Expected1
2
Input
"xaxxaxaxx"
Expected1
3
Input
"axxxaxaxx"
Expected2
4
Input
"xx"
Expected0
5
Input
"13121311"
Expected0
6
Input
"a"
Expected0
Focus radio
Paused · SomaFM · Fluid