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.
For each combination/pair of characters we make a list T based on the input string, keeping only characters from the current pair in the original order.
Then zip(T, T[1:]) will yield tuples of adjoining characters, and if in all these tuples/pairs characters differ then they make a string "of two distinct alternating characters".
And it's the longest since we process combinations in order of character's quantity.
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 →
For each combination/pair of characters we make a list T based on the input string, keeping only characters from the current pair in the original order.
Then zip(T, T[1:]) will yield tuples of adjoining characters, and if in all these tuples/pairs characters differ then they make a string "of two distinct alternating characters".
And it's the longest since we process combinations in order of character's quantity.