public int firstOffendingParenthesis(String input) {
        /*
        Algorithm:
            1. Iterate over all the characters of input String
            2. If character is ')' and stack is not empty then remove element from stack
            3. Else add the position into the stack
            4. After iteration, if stack is empty then return -1 else get the first element and return its value.
         */
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == ')' && !stack.empty()) {
                stack.pop();
            } else {
                stack.push(i);
            }
        }
        return stack.empty() ? -1 : stack.elementAt(0);
    }
A common problem for compilers and text editors is determining whether the parentheses in a string are balanced and properly nested.
For example, the string ((())())() contains properly nested pairs of parentheses, which the strings )()( and ()) do not.
Give an algorithm that returns true if a string contains properly nested and balanced parentheses, and false if otherwise.
For full credit, identify the position of the first offending parenthesis if the string is not properly nested and balanced.
java8/src/main/java/com/shekhargulati/tadm/ch03/Problem3_1.java