Write a method to **recursively** check whether an equation has a balanced number of
left and right parentheses and brackets - (including `(,),[,],{,}`

).

Examples:

`isBalanced("() [] ()") ==> true`

`isBalanced("([)]") ==> false`

Need a **hand?** Try out these hints, one at a time.

A

`Stack`

can be very helpful in solving this problem
You might find the

`indexOf(char)`

method on the `String`

class useful. The `Stack`

class might come in handy as well!
Scan the string from left to right:

1. Whenever an opening bracket is encountered, push it onto the stack.

2. Whenever a closing bracket(parenthesis / curly brace) is encountered, pop one bracket from the stack and compare it with the encountered closing bracket.

2.a. If the two brackets are not of the same type, the expression is not balanced.

2.b. If the two brackets are of the same type, continue scanning.

3. At the end of the scan, the stack should be empty. Otherwise, it's an unbalanced expression.

1. Whenever an opening bracket is encountered, push it onto the stack.

2. Whenever a closing bracket(parenthesis / curly brace) is encountered, pop one bracket from the stack and compare it with the encountered closing bracket.

2.a. If the two brackets are not of the same type, the expression is not balanced.

2.b. If the two brackets are of the same type, continue scanning.

3. At the end of the scan, the stack should be empty. Otherwise, it's an unbalanced expression.

public static boolean isBalanced(String input) { }

**C**

**Java**

**Python**