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 whether two strings can be made equal by copying their characters with the adjacent ones
- Find the character made by adding all the characters of the given string
- Check whether the string S1 can be made equal to S2 with the given operation
- 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
- Quick way to check if all the characters of a string are same
- Check if both halves of the string have same set of characters
- Program to check if first and the last characters of string are equal
- Check if characters of one string can be swapped to form other
- Check whether the frequencies of all the characters in a string are prime or not
- Check if both halves of the string have same set of characters in Python
- Check if the characters of a given string are in alphabetical order
- Check whether count of distinct characters in a string is Prime or not
- Check if characters of a given string can be rearranged to form a palindrome
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.