Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created February 21, 2021 08:07
Show Gist options
  • Save samarthsewlani/843a6bc5e55048308c43b50084d4fac6 to your computer and use it in GitHub Desktop.
Save samarthsewlani/843a6bc5e55048308c43b50084d4fac6 to your computer and use it in GitHub Desktop.
Alternating Characters HackerRank Solution
def alternatingCharacters(s):
count=0
for i in range(1,len(s)): # We start from 1 as there is no previous charcter for 0th index
if s[i]==s[i-1]: # If current character is same as previous charcter
count+=1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment