Remove Duplicates

Level EASY

Given a string S, remove consecutive duplicates from it recursively.

Input Format :
String S
Output Format :
Output string
Constraints :
1 <= |S| <= 10^3
where |S| represents the length of string
Sample Input 1 :
aabccba
Sample Output 1 :
abcba
Sample Input 2 :
xxxyyyzwwzzz
Sample Output 2 :
xyzwz
s= [x for x in input()]
n=len(s)
j=0
res=""
for i in range(1,n):
if s[i] == s[j]:
s[j] = " "
j=j+1
else:
j=j+1
print(res.join(s).replace(" ",""))

Comments

Popular posts from this blog

MySQL Multi Source Master Slave Replication using GTID

Access and modify all the resources of our Wiki.js using WikiJS API

How to setup an Nginx reverse proxy with a SSL certificate in XWIKI