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.
# uses letter1 and letter2 as the combo letters# returns length of longest alternating str with them, 0 if not possibledefgetcombolength(s,letter1,letter2):count=0toggleletter='?'forletterins:ifletter==letter1orletter==letter2:ifletter==toggleletter:return0count+=1toggleletter=letterreturncountdefalternate(s):iflen(s)<=1:return0letters='abcdefghijklmnopqrstuvwxyz'maxcombo=0for(letter1,letter2)in[(letters[j],letters[k])forjinrange(26)forkinrange(j+1,26)]:combo=getcombolength(s,letter1,letter2)maxcombo=max(combo,maxcombo)returnmaxcombo
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Two Characters
You are viewing a single comment's thread. Return to all comments →
Python