A programming problem regarding string manipulation related programming problem of hackerrank interview preparation kit.
The problem description is as follows:
You are given a string containing characters A and B only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.
Your task is to find the minimum number of required deletions.
For example, given the string , AABAAB remove an A at positions 0 and 3 to make ABAB in 2 deletions.
Sample Input
--------------------
5
AAAA
BBBBB
ABABABAB
BABABA
AAABBB
Sample Output
-----------------------
3
4
0
0
4
I solved this problem in java with time complexity of O(n). Let me know in the comment if you more optimized solution than that.