@@ -0,0 +1,994 @@
+package com.interview.string;%0A%0A/**%0A * Remove consecutive duplicate characters%0A * e.g%0A * AABBCDDAAB -%3E ABCDAB%0A * ABBBCCD -%3E ABCD%0A * Test cases%0A * Empty string%0A * all unique%0A * all duplicates%0A * duplicates at certain different places%0A */%0Apublic class RemoveConsecutiveDuplicate %7B%0A%0A    public int removeDuplicates(char input%5B%5D)%7B%0A        int slow = 0;%0A        int fast = 0;%0A        int index = 0;%0A        while(fast %3C input.length)%7B%0A            while(fast %3C input.length && input%5Bslow%5D == input%5Bfast%5D)%7B%0A                fast++;%0A            %7D%0A            input%5Bindex++%5D = input%5Bslow%5D;%0A            slow = fast;%0A        %7D%0A        return index;%0A    %7D%0A    %0A    public static void main(String args%5B%5D)%7B%0A        String str = %22AAABBCCDDDEFGH%22;%0A        char input%5B%5D = str.toCharArray();%0A        RemoveConsecutiveDuplicate rcd = new RemoveConsecutiveDuplicate();%0A        int len = rcd.removeDuplicates(input);%0A        for(int i=0; i %3C len; i++)%7B%0A            System.out.print(input%5Bi%5D + %22 %22);%0A        %7D%0A    %7D%0A%7D%0A

Remove consecutive duplicate characters in string