Created
March 16, 2022 22:34
-
-
Save see-why/90cb8d7482cfe8284d6679ef26671819 to your computer and use it in GitHub Desktop.
HackerRank Alternating Characters challenge solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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