Given a string like '0100011'
and a length = 2
we have to count the frequency of pairs in the string: 00,01,10,11
.
00 -> 2 , 01 -> 2 , 10 ->1 , 11->1
The problem is if I just use the count('00')
function, it doesn't work since it only finds one occurrence: " _ _ 000 _ _"
.
I've been wondering what the right approach to this kind of problem would be, since for the moment i've tried to create some sort of substring checker with 2 pointer(index and length) which goes back and forth to be sure it doesn't miss any combination but it doesn't feel right