class BracketPush {
    companion object {
        fun isValid(inpString: String): Boolean{
            val stack = mutableListOf<Char>()
            val realString = inpString.filter {
                (it == '{') or
                (it == '[') or
                (it == '(') or
                (it == ')') or
                (it == ']') or
                (it == '}') }
            for (i in realString){
                if ((i == '{') or
                        (i == '[') or
                        (i == '(')){
                    stack.add(0, i)
                }
                else {
                    val temp = if (stack.size == 0) {'a'} else {stack.removeAt(0)}
                    when (temp){
                        '(' -> if (i != ')') return false
                        '{' -> if (i != '}') return false
                        '[' -> if (i != ']') return false
                        else -> return false
                    }
                }
            }
            return stack.isEmpty()
        }

    }
}