We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defalternatingCharacters(s):# Counter to count the right characters to form the desired sequenceseqCount=1# Loop on the whole string to count seqCountforiinrange(len(s)-1):#Compare the current character with the next charcter and increase# the counter by 1 if the two characters are alternating (Not equal each other)ifs[i]!=s[i+1]:seqCount+=1#The diffrence between the whole string size and the seqCount is equal to# the number of charcters we should delete to from the desired sequencereturn(len(s)-seqCount)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
Using Python3