guys please say where i have mistaken
t=int(input())
for _ in range(t):
h,l=[int(a) for a in input().split()]
re=int(l)
s=input()
z=0
for i in s:
if i=="0":
z=z+1
else:
if z!=0:
if (re-z)!=0:
re=2*(re-z)
else:
re=re-z
z=0
if re==0:
break
if z!=0:
if (re-z)!=0:
re=2*(re-z)
else:
re=re-z
z=0
if re==0:
print("YES")
else:
print("NO")
1.push all the length of continuous zeroes in a vector (denotes that how much my user can sleep continuously)
2.Now if there are no zero answers is NO
3. else, let prev = h denotes we need this hrs to sleep, now iterate my vector, if my current value (which is basically the length of continuous zeroes ) is less than prev, then I will change my previous to prev = 2 * (prev-vc[i]); (as question said)
Also, one thing is to check sometimes while doing this (prev = 2 * (prev-vc[i]); ) , my prev is greater than h , so now we will set prev to h because from now we will check from that time frame no need to take previously.
otherwise(if vc[i]>prev) will set flag=1 means we get enough continuous hrs to sleep.
in last what I add is to check max continuous zeroes, we r checking here from starting and doing all the operations above may increase my prev, so I directly check whether the max continuous zeroes are greater than equal to h or not, if yes then I will simply sleep in that time frame only.
can someone give a test case which my code might fail to pass because I am still trying but cannot find a test case on which I can improve my code? Any help will be recommended thanks:
Did you add the condition to update H only if the following condition holds true: 2(H-x) < H?
Here’s an example:
Suppose H=5, and at some point x=2,
then it would not be prudent to update H with 2(H-x) because the new value of H will then become
H = 2 * (5 - 2) = 6 which is actually greater than the previous value of SLEEP REQUIRED. In that case, it would be best it we didn’t update the existing value of H. Hope this solves your issue.