public static void main(String args[]){
        RemoveExtraBrackets reb = new RemoveExtraBrackets();
        char input1[] = ")(".toCharArray();
        int pos = reb.remove(input1);
        printArray(input1, pos);
      
        char input1_1[] = ")(".toCharArray();
        pos = reb.removeWithoutExtraSpace(input1_1);
        printArray(input1_1, pos);
      
        char input2[] = "(((abc)(lm)(()".toCharArray();
        pos = reb.remove(input2);
        printArray(input2, pos);
 
        char input2_1[] = "(((abc)(lm)(()".toCharArray();
        pos = reb.removeWithoutExtraSpace(input2_1);
        printArray(input2_1, pos);
 
        char input3[] = "(((c)(l))))(()))".toCharArray();
        pos = reb.remove(input3);
        printArray(input3, pos);
 
        char input3_1[] = "(((c)(l))))(()))".toCharArray();
        pos = reb.removeWithoutExtraSpace(input3_1);
        printArray(input3_1, pos);
 
        char input4[] = "((((".toCharArray();
        pos = reb.remove(input4);
        printArray(input4, pos);
 
        char input4_1[] = "((((".toCharArray();
        pos = reb.removeWithoutExtraSpace(input4_1);
        printArray(input4_1, pos);
 
        char input5[] = "))))".toCharArray();
        pos = reb.remove(input5);
        printArray(input5, pos);
 
        char input5_1[] = "))))".toCharArray();
        pos = reb.removeWithoutExtraSpace(input5_1);
        printArray(input5_1, pos);

        char input6[] = "((Test))(Great)".toCharArray();
        pos = reb.remove(input6);
        printArray(input6, pos);
 
        char input6_1[] = "((Test))(Great)".toCharArray();
        pos = reb.removeWithoutExtraSpace(input6_1);
        printArray(input6_1, pos);
 
    }
This method does not uses stack and does inplace conversion
src/com/interview/stackqueue/RemoveExtraBrackets.java