Binary string reduction in Python

Asked: Sudeep |Category: Python

x=int(input("Enter the value of x : "))
for i in range(x):
    n=int(input("Enter the value of n : "))
    y=input("Enter the value of y : ")
    l=list(y)
    k=0
    while(len(l)!=0):
        p=[]
        s=l[0]
        p.append(0)
        t=0
        u=0
        for j in l:
            if(j!=s):
                s=j
                p.append(t)
            t+=1
        for j in p:
            l.pop(j-u)
            u=u+1
        k+=1
    print(k)
8 views

Recent Posts

See All

Lists | HACKER RANK

Asked: Rahul Kumar Ranjan |Category: Python n=int(input()) l=[] for i in range (n): x=input().split(" ") com=x[0] if com=="insert": l.insert(int(x[1]),int(x[2])) elif com=="print": print(l) elif com==

"Believe you can and you're halfway there"