# KLXOR-runtime error

for a in range(int(input())):
n,k=map(int,input().split())
s=input()
lst1=[]
for i in range(((len(s)-k)+1)):
s1=s[i:k+i]
lst1.append(s1)
x=0
for j in range(len(lst1)):
x=x^int(lst1[j])
x=str(x)
print(x.count(“1”))
I am getting runtime error can anyone tell me whyKLXOR - Editorial

I think you’ll find this video to be helpful,
KLXOR | AGAIN XOR PROBLEM | December CodeDrive 2021 | Problem Solutions | CodeChef

Here’s a python code

``````T = int(input())

for _ in range(T):

n,k = input().split()
s = input()

n = int(n)
k = int(k)

ans = 0
c = 0

for i in range(0,n-k):

if s[i] == '1':
c += 1

for j in range(0,k):

if s[n-k+j] == '1':
c += 1

if c%2 != 0:
ans += 1

if s[j] == '1':
c -= 1

print(ans)
``````

a better approach

``````def func():
n, k = map(int, input().split())
c = 0
ans = 0
s = input()
for i in range(n-k+1):
if s[i] == '1':
c += 1
#print(n-k, end = " ")
#print(c)
if c%2 == 1:
ans += 1
for i in range(n-k+1, n):
if s[i-n+k-1] == '1':
c -= 1
if s[i] == '1':
c += 1
if c%2 == 1:
ans += 1
#print(i, end = " ")
#print(c)
print(ans)

t = int(input())
for i in range(t):
func()

``````