Given a string str, the task is to check whether the given string is made up of only two alternating characters.
Input: str = “ABABABAB”
Input: str = “XYZ”
Approach: In order for the string to be made up of only two alternating characters, it must satisfy the following conditions:
- All the characters at odd indices must be same.
- All the characters at even indices must be same.
- str != str (This is because string of type “AAAAA” where a single character is repeated a number of time will also satisfy the above two conditions)
Below is the implementation of the above approach:
- Check if a two character string can be made using given words
- Check if string can be made lexicographically smaller by reversing any substring
- Check whether second string can be formed from characters of first string
- Check if both halves of the string have same set of characters
- Quick way to check if all the characters of a string are same
- Program to check if first and the last characters of string are equal
- Check if both halves of the string have same set of characters in Python
- Check if characters of one string can be swapped to form other
- Check if the characters of a given string are in alphabetical order
- Check whether the frequencies of all the characters in a string are prime or not
- Check if string follows order of characters defined by a pattern or not | Set 3
- Check if a string has all characters with same frequency with one variation allowed
- Check if string follows order of characters defined by a pattern or not | Set 2
- Check if string follows order of characters defined by a pattern or not | Set 1
- Check whether count of distinct characters in a string is Prime or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.