public int removeWithoutExtraSpace(char input[]){
        int openBrackets = 0;
        int closeBrackets = 0;
        
        int index = 0;
        for(int i=0; i < input.length; i++){
            if(input[i] != '(' && input[i] != ')'){
                input[index++] = input[i]; 
                continue;
            }
            if(input[i] == '('){
                openBrackets++;
                input[index++] = input[i];
            }else {
                //add close bracket to input only if it is 
                //less than open bracket count.
                if(closeBrackets < openBrackets){
                    input[index++] = input[i];
                    closeBrackets++;
                }
            }
        }
        
        //iterate through result get rid of extra open brackets if any towards
        //the end
        if(openBrackets > closeBrackets){
            int newIndex = 0;
            int seenOpenBracket = 0;
            for(int i=0; i < index; i++){
                if(input[i] == '('){
                    seenOpenBracket++;
                }
                if(input[i] != '(' || seenOpenBracket <= closeBrackets){
                    input[newIndex++] = input[i];
                }
            }
            index = newIndex;
        }
        return index;
    }
This method does not uses stack and does inplace conversion
src/com/interview/stackqueue/RemoveExtraBrackets.java