Test Cases Are Failing For StringRemoveDuplicates

I want to know the test cases which are failing. There are 4 testcases and my code only passes 1. What are the remaining test cases which are failing??

import java.util.Scanner;

public class StringRemoveDuplicates {

public static void main(String[] str){
	
	Scanner sc = new Scanner(System.in);
	String input = sc.nextLine();
	
	System.out.println(stringRemoveDuplicates(input,0));
}

private static String stringRemoveDuplicates(String input,int selectedIndex){
	
	if(selectedIndex == input.length() - 1 ){
		String result = input.substring(selectedIndex,input.length());
		return result;
	
	}
			
	for(int x=selectedIndex; x<input.length()-1 ; ++x){
		
		String currentchar = input.substring(x,x+1);
		String nextchar = input.substring(x+1,x+2);
	
		if(currentchar.equalsIgnoreCase(nextchar)){
			StringBuffer sb = new StringBuffer(input.substring(0,x+1));
			sb.append(input.substring(x+2));
			input = sb.toString();
		}
		
		stringRemoveDuplicates(input,x+1);
	}
	
	return input;
}

}

Hey @connectrajanjain Testcases like these are failing : aaaabbccccaaaabcbacba
correct output = abcabcbacba
you output = aabccaabcbacba

import java.util.Scanner;
public class StringRemoveDuplicates {

	public static void main(String[] str){
	
	Scanner sc = new Scanner(System.in);
	String input = sc.nextLine();
	
	System.out.println(stringRemoveDuplicates(input,0));
}

private static String stringRemoveDuplicates(String input,int selectedIndex){
	
		if(selectedIndex == input.length() - 1 ){
			String result = input.substring(selectedIndex,input.length());
			return result;
		
		}
				
		for(int x=selectedIndex; x<input.length()-1 ; ++x){
			
			String currentchar = input.substring(x,x+1);
			String nextchar = input.substring(x+1,x+2);
		
			if(currentchar.equalsIgnoreCase(nextchar)){
				StringBuffer sb = new StringBuffer(input.substring(0,x+1));
				sb.append(input.substring(x+2));
				input = sb.toString();
				stringRemoveDuplicates(input,x);
			}
			else
				stringRemoveDuplicates(input,x+1);
		}
		
		return input;
	}
	
}

I am not able to identify the problem. Why my code is not working ? Can you point the problem.

Hey @connectrajanjain You can refer to my code :
static String removeDuplicate( char str[], int n)

{

// Used as index in the modified string

int index = 0 ;

// Traverse through all characters

for ( int i = 0 ; i < n; i++)

{

// Check if str[i] is present before it

int j;

for (j = 0 ; j < i; j++)

{

if (str[i] == str[j])

{

break ;

}

}

if (j == i)

{

str[index++] = str[i];

}

}

return String.valueOf(Arrays.copyOf(str, index));

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Recursion is required. This is recursion exercise. Can you please check my solution or provide solution with recursion.