@@ -0,0 +1,1615 @@
+package algorithms.strings;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * Shashank likes strings in which consecutive characters are different. For%0D%0A * example, he likes ABABA, while he doesn't like ABAA. Given a string%0D%0A * containing characters A and B only, he wants to change it into a string he%0D%0A * likes. To do this, he is allowed to delete the characters in the string.%0D%0A * %0D%0A * Your task is to find the minimum number of required deletions.%0D%0A * %0D%0A * Input Format: %0D%0A * The first line contains an integer T, i.e. the number of test cases.%0D%0A * The next T lines contain a string each.%0D%0A * %0D%0A * Output Format: %0D%0A * For each test case, print the minimum number of deletions required.%0D%0A * %0D%0A * Constraints:* %0D%0A * 1 %3C= T %3C= 10%0D%0A * 1 %3C= length of string %3C= 105%0D%0A * %0D%0A * Sample Input: %0D%0A * 5%0D%0A * AAAA%0D%0A * BBBBB%0D%0A * ABABABAB%0D%0A * BABABA%0D%0A * AAABBB%0D%0A * %0D%0A * Sample Output: %0D%0A * 3%0D%0A * 4%0D%0A * 0%0D%0A * 0%0D%0A * 4%0D%0A */%0D%0Apublic class AlternatingCharacters %7B%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        %0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        %0D%0A        int numCases = sc.nextInt();%0D%0A        %0D%0A        for (int i = 0; i %3C numCases; i++) %7B%0D%0A            String input = sc.next();%0D%0A            System.out.println(numDeletions(input));%0D%0A        %7D%0D%0A        sc.close();%0D%0A    %7D%0D%0A    %0D%0A    private static int numDeletions(String str) %7B%0D%0A        %0D%0A        int deletionsRequired = 0;%0D%0A        for (int i = 1; i %3C str.length(); i++) %7B%0D%0A            if (str.charAt(i) == str.charAt(i - 1)) %7B%0D%0A                deletionsRequired++;%0D%0A            %7D%0D%0A        %7D%0D%0A        return deletionsRequired;%0D%0A    %7D%0D%0A%7D

Add AlternatingCharacters