<jupyter_start><jupyter_text>Balanced Brackets![image](https://user-images.githubusercontent.com/50367487/83854988-6ad93c80-a752-11ea-9fad-081c3c851fed.png)<jupyter_code>#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the isBalanced function below.
def isBalanced(s):
    lst = []
    for i in s:
        if i in "{[(":
            lst.append(i)
        elif i in "}])" and lst:
            val = lst.pop()
            if not (1 <= ord(i) - ord(val) <= 2):
                return "NO"
        else:
            return "NO"
    if lst: return "NO"
    return "YES"

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    t = int(input())

    for t_itr in range(t):
        s = input()

        result = isBalanced(s)

        fptr.write(result + '\n')

    fptr.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0429732868757259, 'mean_word_length': 2.3026819923371646, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '281354', 'license': 'MIT', 'n_tokens_mistral': 346, 'n_tokens_neox': 315, 'n_words': 71, 'path': 'Interview Preparation Kit/9. Stacks and Queues/Balanced Brackets.ipynb', 'repo_name': 'Nam-SH/HackerRank', 'size': '861'}