top of page
Click here to go to the home page of AskTheCode.

Binary string reduction in Python

Team ATC

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)

Recent Posts

See All

Comments


bottom of page