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.
- Prepare
- Algorithms
- Strings
- Two Characters
- Discussions
Two Characters
Two Characters
Sort by
recency
|
1137 Discussions
|
Please Login in order to post a comment
This is my Python solution ā Explanation: 1. I first generate all unique character pairs from the input string. 2. For each pair, I build a filtered string that only includes those two characters. 3. I then check if the filtered string alternates properly (i.e., no repeated consecutive characters). 4. If it passes, I update the maximum length found so far. 5. In the end, return the longest valid alternating string length or 0 if none found.
š Note: Although this problem is tagged "Easy", it requires thoughtful implementation. Iād say it feels more like a Medium problem due to the character pairing and validation logic.
Hope this helps others! š
Here is my c++ easy solution, explantion here : https://youtu.be/WAPtXpj-PSU
Here is my approach