Let's say I have an input String as "aaabbaccd". I need to design a program which remove all the adjacent duplicates from my output. So taking the example of above string, the output would be :
1. First output that I would get after removing adjacent duplicates would be "aad" (Removed aabbcc from my input).
2. In the second pass, it would remove aa from my string and make my output as "d".

So far, what I could design the below code :

```
String input="aaabbaccd";

    String[] arr=input.split("");

    int n=arr.length;
    for(int i=0;i<n;i++) {
        if(i==arr.length-1) {
            if(arr[i-1].equals(arr[i])) {
                break;
            }
            else {
                System.out.print(arr[i]+ "");
                break;
            }
        }
        if(arr[i].equals(arr[i+1])) {
            i=i+1;
            continue;
        }
        if(!arr[i].equals(arr[i+1])) {
            System.out.print(arr[i]+ "");
        }
    }

```

The problem with this code is that it gives me output as aad. I cannot comprehend how to do the second pass on my code. Maybe recursion is something that I need to implement in this code. Please help me how to implement recursion in this code.