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.
Good solution, all tests passed using this approach. For those who didn't understand the logic -
First of all identify all the distinct characters in string. To do this, we have removed duplicates from original string using a set.
Now iterate over distinct characters in pairs, use the string having no duplicates which we generated in above step.
Form the potential final string having this pair of characters. To do this, iterate over original string and check for occurrences of these two characters and add them to potential string.
Now check the validity of potential string for alternate characters
If potential string is valud, keep count of max length of such strings to get the final answer.
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 →
Good solution, all tests passed using this approach. For those who didn't understand the logic -