# Runtime Error (OTHER), LRNDSA01 - CONFLIP

I’m lost

def switch(l,i):
if l[i] == 1:
l[i] = 2
elif l[i] == 2:
l[i] = 1

for t in range(int(input())):
g = int(input())

for j in range(g):
i, n, q = map(int,input().split())

# Round starts
coins = [i] * n     # List of coins initialized
for k in range(n):
#print("k:",k,"Before:",coins)
for change in range(k+1):
switch(coins, change)
#print("k:",k,"After:",coins)

# Counting starts
tails = 0
for coin in coins:
if coin == 1:
elif coin == 2:
tails += 1

if q == 1:
elif q == 2:
print(tails)


You should run some test cases on paper, with binary numbers ( H=1 \: , T = 0) it is easier to visualize that the configuration for the run N_{k-1} is always the same.
Basically the number of zeros and ones is always \frac{N}{2} except the case in which N\%2 \neq 0.

Think about it and then you can have a look at my solution (C++)

if(i != q)cout <<  n/2 + n%2  << endl;
else cout << n - (n/2 + n%2) << endl;

1 Like

Thanks for the quick reply and knocking some sense into me!

1 Like