Skip to content

Instantly share code, notes, and snippets.

@see-why
Created March 16, 2022 22:34
Show Gist options
  • Save see-why/90cb8d7482cfe8284d6679ef26671819 to your computer and use it in GitHub Desktop.
Save see-why/90cb8d7482cfe8284d6679ef26671819 to your computer and use it in GitHub Desktop.
HackerRank Alternating Characters challenge solution
# https://www.hackerrank.com/challenges/alternating-characters/problem?isFullScreen=true
def alternatingCharacters(s):
# Write your code here
result=0
if 'A' not in s or 'B' not in s:
result = len(s)-1
return result
i=0
while i<(len(s)-1):
if s[i+1]==s[i]:
result+=1
i+=1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment