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.
This should be a reasonable solution, without regex:
fromitertoolsimportcombinationsdefalternate(s):acceptable_solutions=[""]# Get all 2-letter combinations and iterate over themavailable_combs=list(combinations(set(s),2))forcombinavailable_combs:# remove characters not in in the set we are testingclean_str="".join(charforcharinsifcharincomb)# checks if all pairs from (0,1) to (-2, -1) are not the same,ifall(clean_str[i-1]!=clean_str[i]foriinrange(1,len(clean_str))):acceptable_solutions.append(clean_str)# get the len of each item and return their maxreturnmax(len(x)forxinacceptable_solutions)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
This should be a reasonable solution, without regex: