Recursive check of bracket balance
Python
Medium
recursion
Task «Recursive check of bracket balance»
Write a recursive function to check the correctness of bracket placement in a string. The string consists only of the characters '(', ')', '{', '}', '[' and ']'. It is necessary to determine whether the sequence of brackets is balanced (each opening bracket has a corresponding closing bracket of the same type, and the nesting is correct). Use recursion without a stack (you can pass an index and nesting level). Constraints: string length up to 100 characters.
Input Format
A single line containing a sequence of brackets.
Output Format
Output 'YES' if the brackets are balanced, otherwise 'NO'.
Examples
Example 1
INPUT
({[]})
OUTPUT
YES
Example 2
INPUT
({)}
OUTPUT
NO
main.py