description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, a, n):
ans = 0
m1 = a[0] + 0
m2 = -a[0] + 0
for i in range(n):
m1 = min(m1, a[i] + i)
m2 = min(m2, -a[i] + i)
ans = max(ans, a[i] + i - m1)
ans = max(ans, -a[i] + i - m2)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR B... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
max1, min1, max2, min2 = arr[0], arr[0], arr[0], arr[0]
for i in range(1, n):
max1 = max(max1, arr[i] - i)
min1 = min(min1, arr[i] - i)
max2 = max(max2, arr[i] + i)
min2 = min(min2, arr[i] + i)
re... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN FU... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
ans = -10000000
mx = -10000000
mn = 10000000
for i in range(n):
mx = max(mx, arr[i] - i)
mn = min(mn, arr[i] + i)
v1 = arr[i] + i - mn
v2 = mx - (arr[i] - i)
ans = max(ans, max... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
r = float("-inf")
maxi = float("-inf")
mini = float("+inf")
for i in range(len(arr)):
maxi = max(maxi, arr[i] - i)
mini = min(mini, arr[i] + i)
v1 = arr[i] + i - mini
v2 = maxi - arr[i] + ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
cmin = cmax = arr[0]
ans = 0
for i in arr[1:]:
cmin = min(cmin - 1, i)
cmax = max(cmax + 1, i)
ans = max(ans, i - cmin, cmax - i)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
A1 = []
A2 = []
for i in range(n):
A1.append(arr[i] - i)
A2.append(arr[i] + i)
return max(max(A1) - min(A1), max(A2) - min(A2)) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
a = [(x - i) for i, x in enumerate(arr)]
b = [(x + i) for i, x in enumerate(arr)]
return max(max(a) - min(a), max(b) - min(b)) | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, a, n):
for i in range(n):
a[i] += i
m1 = max(a)
m2 = min(a)
for i in range(n):
a[i] -= 2 * i
m3 = max(a)
m4 = min(a)
return max(m1 - m2, m3 - m4) | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
max1 = -100000
max2 = -10000
min1 = 10000
min2 = 10000
for i in range(n):
max1 = max(max1, arr[i] + i)
min1 = min(min1, arr[i] + i)
max2 = max(max2, arr[i] - i)
min2 = min(min2, ar... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR ... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, a, n):
ans = -int(1e56)
mx = -int(1e56)
mi = int(1e56)
for i in range(n):
mx = max(mx, a[i] - i)
mi = min(mi, a[i] + i)
ans = max(ans, a[i] + i - mi, mx - (a[i] - i))
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VA... |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
ans = 0
maxx = minn = arr[0]
for i in range(n):
newMaxx = arr[i] - i
newMinn = arr[i] + i
ans = max(ans, maxx - newMaxx, newMinn - minn)
maxx = max(maxx, newMaxx)
minn = min(minn, newM... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |.
Example 1:
Input :
n = 3
arr[ ] = {1, 3, -1}
Output: 5
Explanation:
Maximum difference comes from indexes
1, 2 i.e ... | class Solution:
def maxDistance(self, arr, n):
maxi1 = -pow(2, 32) + 1
mini1 = pow(2, 32) - 1
for i in range(n):
cur = arr[i] - i
if maxi1 < cur:
maxi1 = cur
if mini1 > cur:
mini1 = cur
ans1 = maxi1 - mini1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | for _ in range(int(input())):
l, correct = [], True
for c in input():
if c in "{([":
l.append(c)
elif c in "})]":
if len(l) > 0 and (
c == "}"
and l[-1] == "{"
or c == ")"
and l[-1] == "("
or ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | for _ in range(int(input())):
s = input()
l = []
flag = True
for i in s:
if i == "(" or i == "{" or i == "[":
l.append(i)
elif i == ")":
if len(l) == 0 or l.pop() != "(":
flag = False
break
elif i == "}":
if len(... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | map = {"}": "{", "]": "[", ")": "("}
def balanced(parens):
if len(parens) % 2 != 0:
return False
stack = []
for paren in parens:
if paren in "{[(":
stack.append(paren)
else:
if len(stack) == 0:
return False
if map[paren] != stack.... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR FUNC_CALL VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CAL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | d = {"}": "{", "]": "[", ")": "("}
for _ in range(int(input())):
isBalanced = True
stack = []
for i, c in enumerate(input()):
if c == "{" or c == "[" or c == "(":
stack.append(c)
elif not stack or d[c] != stack.pop():
isBalanced = False
break
print("YE... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRIN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | N = int(input())
for i in range(N):
my_stack = []
my_list = list(input().strip())
for j in range(len(my_list)):
if len(my_stack) == 0:
my_stack.append(my_list[j])
elif (
my_stack[-1] == "{"
and my_list[j] == "}"
or my_stack[-1] == "["
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING VAR VAR STRING VAR NUMBER STRING VAR VAR STRING VAR NUMBER STRING VAR VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | N = int(input())
opposites = {"}": "{", "]": "[", ")": "("}
for i in range(N):
s = input().strip()
stack = []
for ch in s:
if len(stack) > 0 and stack[-1] == opposites.get(ch):
stack.pop()
else:
stack.append(ch)
if len(stack) > 0:
print("NO")
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FU... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
T = int(input())
strings = []
for i in range(0, T):
s = str(input().strip(" "))
strings.append(s)
def check(s):
if s.strip(" ") == "":
return "NO"
curve = 0
round_ = 0
square = 0
who_was_last = []
for j in range(0, len(s)):
if s[j] == "(":
round_... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR STRING STRING RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input())
while T > 0:
T -= 1
s = input()
lefts = ["{", "(", "["]
rights = ["}", ")", "]"]
goodpairs = list(zip(lefts, rights))
stack = []
passcase = True
for c in s:
if c in lefts:
stack.append(c)
elif not stack:
passcase = False
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER AS... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input().strip())
for t in range(T):
l = input().strip()
ps = []
valid = 1
for p in l:
if p in ["{", "(", "["]:
ps.append(p)
elif not len(ps):
valid = 0
break
else:
lp = ps.pop()
if not (
lp == "{"... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRI... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def closes(close_char, open_char):
return (
close_char == "]"
and open_char == "["
or close_char == "}"
and open_char == "{"
or close_char == ")"
and open_char == "("
)
def run_cmd(command):
openChars = []
for char in command:
if char == "{" or c... | FUNC_DEF RETURN VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def opposite(c):
if c == ")":
return "("
if c == "}":
return "{"
if c == "]":
return "["
n = int(input())
for _ in range(n):
S = input().strip()
good = True
cstack = []
for c in S:
if c in ["{", "[", "("]:
cstack.append(c)
elif cstack and... | FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR FUNC... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def matcher(b):
if b == "[":
return "]"
elif b == "{":
return "}"
elif b == "(":
return ")"
else:
return None
t = int(input())
for i in range(t):
usr = input()
valid = "YES"
i = 0
s = []
if len(usr) % 2 != 0:
valid = "NO"
while valid == "... | FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING WHILE VAR STR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | i = int(input())
stack = []
oo = {"{": "}", "(": ")", "[": "]"}
oc = {"}": "{", ")": "(", "]": "["}
for x in range(i):
r = input()
isOk = True
for c in r:
if c in oo:
stack.append(c)
isOk = False
else:
if len(stack) == 0:
isOk = False
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def checkParenthesis(line):
list = []
for i in range(len(line)):
if line[i] == "{" or line[i] == "(" or line[i] == "[":
list.append(line[i])
if line[i] == "}":
if len(list) == 0:
print("NO")
return
popped = list.pop()
... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR STRING IF FUNC_CAL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def main():
n = int(input().strip())
for _ in range(n):
s = input().strip()
stack = []
balanced = True
for ch in s:
if ch in ["(", "{", "["]:
stack.append(ch)
elif len(stack) == 0:
balanced = False
break
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
class Stack:
def __init__(self):
self.list = []
def push(self, arg):
self.list.append(arg)
def pop(self):
return self.list.pop()
def size(self):
return len(self.list)
def isEmpty(self):
return len(self.list) == 0
def check_parentheses(param... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING EXPR F... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def last(lst):
if len(lst) > 0:
return lst[len(lst) - 1]
else:
return None
def check(string):
parens = []
for char in string:
if char == "{":
parens.append("{")
elif char == "[":
parens.append("[")
elif char == "(":
parens.app... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NONE FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING IF FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR RETURN NUM... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def IsBalanced(S):
stack = []
for c in S:
if c == "(" or c == "[" or c == "{":
stack.append(c)
else:
if len(stack) == 0:
print("NO")
return
item = stack.pop()
if (
item == "("
and c ==... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check_brackets(inp):
l = []
flag = 1
for i in inp:
if i == "(" or i == "{" or i == "[":
l.append(i)
elif i == ")":
if len(l) > 0 and l.pop() == "(":
pass
else:
flag = 0
break
elif i == "}":
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FU... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
N = int(sys.stdin.readline())
openBracket = ["{", "[", "("]
closeBracket = ["}", "]", ")"]
def solution(line):
stack = []
for c in line:
if c in openBracket:
stack.append(c)
if c in closeBracket:
try:
old = stack.pop(-1)
except Ex... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR RETURN STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING IF FUNC_CALL VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check_case(string):
lngth = len(string)
opn = ["[", "{", "("]
clos = ["]", "}", ")"]
if lngth % 2 != 0 or string[0] in clos:
return "NO"
balanced_pairs = list("".join(x) for x in zip(opn, clos))
pairs = []
stack = []
for parenth in string:
if parenth in opn:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR I... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | ouvre = {"{", "[", "("}
correspondance = {"}": "{", "]": "[", ")": "("}
N = int(input())
for i in range(N):
ok = True
stack = list()
for c in input():
if c in ouvre:
stack.append(c)
elif len(stack) == 0 or correspondance[c] != stack.pop(-1):
print("NO")
ok... | ASSIGN VAR STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input())
matches = {"{": "}", "(": ")", "[": "]"}
def balanced(string):
s = []
for char in string:
if char in matches:
s.append(char)
elif len(s) == 0 or matches[s.pop(-1)] != char:
return False
return len(s) == 0
for _ in range(T):
print("YES" if bala... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
for i in range(n):
stack = []
s = input()
closed = True
for c in s:
if c in ["{", "[", "("]:
stack.append(c)
else:
if len(stack) == 0:
closed = False
break
if c == "}" and stack[-1] == "{":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR NUMBER STRING... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
i = 0
open = ["{", "[", "("]
close = ["}", "]", ")"]
while i < n:
line = input()
p = []
balanced = True
for x in line:
if x not in close:
p.append(x)
else:
if len(p) == 0:
balanced = False
break
prev = p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
rd = int(sys.stdin.readline().rstrip())
s = []
parant = {"{": "}", "(": ")", "[": "]", "}": "{", ")": "(", "]": "["}
for x in range(0, rd):
st = sys.stdin.readline().rstrip()
s = []
for ch in st:
if len(s) > 0:
if parant[s[-1]] != ch:
s.append(ch)
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR EX... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Stack:
def __init__(self):
self.items = []
def is_empty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[-1]
def size(self):
return len... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF RETURN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR ASSIGN VAR NUMBER A... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input())
while T != 0:
s = input()
l = len(s)
f = 0
stack = []
for i in s:
if i == "(" or i == "{" or i == "[":
stack.append(i)
try:
if i == ")" and stack[-1] == "(":
f += 1
stack.pop()
elif i == "}" and stac... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR IF VAR STRING VAR NUMBER STRING VAR NUMBER ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input().strip())
d = {")": "(", "}": "{", "]": "["}
for i in range(n):
A = [x for x in input().strip()]
q = []
for a in A:
if a in d.values():
q.append(a)
elif len(q) == 0:
print("NO")
break
elif q.pop() != d[a]:
print("NO")
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def delimiters(brackets):
if len(brackets) % 2 != 0:
return False
stack = []
for b in brackets:
if b == "(" or b == "[" or b == "<" or b == "{":
stack.append(b)
elif len(stack) == 0:
return False
elif b == ")" and stack[len(stack) - 1] == "(":
... | FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRI... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | t = int(input())
for i in range(t):
s = input()
l = len(s)
b = []
T = True
for j in range(l):
if s[j] == "{" or s[j] == "(" or s[j] == "[":
b.append(s[j])
elif s[j] == "}":
if len(b) == 0:
print("NO")
T = False
b... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR S... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input().strip())
bracketStrings = []
for i in range(n):
bracketStrings.insert(i, input())
openingBrackets = ["(", "[", "{"]
closingBrackets = [")", "]", "}"]
for bracketString in bracketStrings:
errors = False
stack = []
for bracket in bracketString:
if bracket in openingBrackets:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | o = "{[("
c = "}])"
for _ in range(int(input())):
s = []
for e in input():
if e in o:
s.append(e)
elif not len(s) or c[o.index(s.pop())] != e:
print("NO")
break
else:
if len(s):
print("NO")
else:
print("YES") | ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def is_balanced(s):
p = []
m = {"}": "{", "]": "[", ")": "("}
for c in s:
if c in "{[(":
p.append(c)
continue
if p and m[c] == p.pop():
continue
else:
return "NO"
if p:
return "NO"
return "YES"
for _ in range(int(input... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR RETURN STRING IF VAR RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
for i in range(n):
test = input()
res = [0]
for j in range(len(test)):
if (
len(res) != 0
and (test[j] == ")") & (res[len(res) - 1] == "(")
or (test[j] == "}") & (res[len(res) - 1] == "{")
or (test[j] == "]") & (res[len(res) - 1] == "[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING BIN_OP VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING BIN_OP VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def calculate(parentheses):
opened = ["(", "{", "["]
pairs = [("(", ")"), ("{", "}"), ("[", "]")]
stack = []
for i in parentheses:
if i in opened:
stack.append(i)
else:
if not stack:
return False
if (stack.pop(), i) not in pairs:
... | FUNC_DEF ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def parentheses(exp):
stack = []
for x in exp:
if x == "[" or x == "{" or x == "(":
stack.append(x)
elif x == "]":
if len(stack) != 0 and stack[-1] == "[":
stack.pop()
else:
return "NO"
elif x == "}":
if len(... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN STRING IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN STRING IF VAR STRING IF FUNC_CALL VAR VAR NUM... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check():
stack = []
s = input()
for c in s:
if c == "(":
stack.append(0)
elif c == ")":
if len(stack) > 0 and stack[-1] == 0:
stack.pop()
else:
return -1
elif c == "[":
stack.append(2)
elif c ... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR RETURN NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR RETURN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check(stack):
accept = ["{}", "[]", "()"]
for c in stack:
if c not in accept:
return "NO"
return "YES"
def meow(s):
opens = ["{", "[", "("]
closes = ["}", "]", ")"]
stack = []
retVal = []
length = len(s)
if length % 2 != 0 or s[0] in closes:
return "... | FUNC_DEF ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR IF VAR VAR RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR RETURN STRING FOR VAR VAR IF VAR VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
for _ in range(0, n):
stack = []
braces = list(input())
balanced = True
for brace in braces:
if brace == "(" or brace == "{" or brace == "[":
stack.append(brace)
elif len(stack) > 0:
top = stack[len(stack) - 1]
if (
top... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def match(a, b):
return a == "(" and b == ")" or a == "[" and b == "]" or a == "{" and b == "}"
def is_valid(string):
stack = []
try:
for c in string:
if c in ("(", "[", "{"):
stack.append(c)
elif not match(stack.pop(), c):
return False
... | FUNC_DEF RETURN VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CAL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def isOpenClose(c1, c2):
if c1 == "(" and c2 == ")":
return True
if c1 == "[" and c2 == "]":
return True
if c1 == "{" and c2 == "}":
return True
return False
def isOpen(c):
if c == "(" or c == "[" or c == "{":
return True
return False
n = int(input())
for i in... | FUNC_DEF IF VAR STRING VAR STRING RETURN NUMBER IF VAR STRING VAR STRING RETURN NUMBER IF VAR STRING VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
t = int(input().strip())
for i in range(t):
line = input().strip()
stack = []
for ch in line:
if ch in "})]":
try:
top = stack.pop()
if (
top == "{"
and ch != "}"
or top == "("
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input().strip())
def isCorrectBraces(br):
stk = []
for ch in val:
if ch in ("{", "(", "["):
stk.append(ch)
elif ch == "}":
if len(stk) == 0 or stk.pop() != "{":
return False
elif ch == ")":
if len(stk) == 0 or stk.pop() != "("... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING RETURN NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER F... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | num = int(input())
lst_in = [input() for i in range(num)]
cl_op = {"}": "{", ")": "(", "]": "["}
def is_balanced(seq):
stack = []
for s in seq:
if s in cl_op.values():
stack.append(s)
elif s in cl_op.keys() and len(stack) > 0 and stack.pop() == cl_op[s]:
continue
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN FUNC_C... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
for i in range(n):
string = input()
balanced = True
stack = []
for c in string:
if c == "{":
stack.append("}")
elif c == "(":
stack.append(")")
elif c == "[":
stack.append("]")
elif not stack or stack.pop() != c:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUM... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
dict = {"{": "}", "(": ")", "[": "]"}
for _ in range(n):
s = input()
stack = []
p = True
for i in s:
if i in "({[":
stack.append(i)
elif not (stack and dict[stack.pop()] == i):
p = False
break
print("YES" if not stack and p else "N... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
def match(open_par, close_par):
return (
open_par == "("
and close_par == ")"
or open_par == "["
and close_par == "]"
or open_par == "{"
and close_par == "}"
)
num_lines = eval(input())
lines = []
for line in range(num_lines):
lines.append(input... | IMPORT FUNC_DEF RETURN VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balanced_braces(s):
braces = []
for brace in s:
if brace in "{[(":
braces.append(brace)
else:
try:
if brace == "}" and braces[-1] == "{":
braces.pop()
elif brace == "]" and braces[-1] == "[":
brac... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIG... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def isBalanced(b):
stack = []
balanced = True
for i in b:
if i == "(" or i == "{" or i == "[":
stack.append(i)
elif len(stack) > 0:
if (
i == ")"
and stack[-1] == "("
or i == "}"
and stack[-1] == "{"
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER RETUR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check_if_valid(brackets):
valid_bracket_pairs = {"{": "}", "[": "]", "(": ")"}
stack = []
for element in brackets:
if element in valid_bracket_pairs.keys():
stack.append(valid_bracket_pairs[element])
elif len(stack) > 0 and element == stack[-1]:
stack.pop()
... | FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN STRING IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | match = {"}": "{", "]": "[", ")": "("}
T = int(input())
for _ in range(T):
s = input()
stack = []
for ch in s:
if ch in "{[(":
stack.append(ch)
elif not stack or match[ch] != stack.pop():
print("NO")
break
else:
print("NO" if stack else "YES") | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING STRING |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Stack:
def __init__(self):
self.arr = []
def push(self, val):
self.arr.append(val)
def pop(self):
size = len(self.arr)
if size > 0:
popval = self.arr[size - 1]
self.arr.pop()
return popval
else:
return ""
d... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR RETURN STRING FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def main():
t = input()
items = []
items.append(t[0])
res = True
for i in range(1, len(t)):
if t[i] == "(" or t[i] == "{" or t[i] == "[":
items.append(t[i])
elif items.__len__() != 0:
if t[i] == ")" and items[items.__len__() - 1] == "(":
items.... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | open_paren_match = {"{": "}", "(": ")", "[": "]"}
def parens_match(left_paren, right_paren):
return open_paren_match[left_paren] == right_paren
tests_cnt = int(input().strip())
for _ in range(tests_cnt):
s = list(input().strip())
paren_stack = [s.pop()]
output = "YES"
while s:
paren = s[... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FUNC_DEF RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR ASSIGN VAR VAR NUMBER IF VAR VAR IF VAR IF FUNC_CALL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | o = ["{", "[", "("]
c = ["}", "]", ")"]
t = int(input())
for i in range(t):
s = input()
b = True
a = []
for j in range(len(s)):
if s[j] in o:
a.append(s[j])
elif len(a) > 0 and o.index(a[len(a) - 1]) == c.index(s[j]):
del a[len(a) - 1]
else:
b ... | ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input().strip())
strings = []
for i in range(n):
strings.append(input().strip())
def pair(in_string):
if in_string == "{":
return "}"
if in_string == "(":
return ")"
if in_string == "[":
return "]"
for string in strings:
trouble = False
t1_stack = []
for c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR LIST STRING STRING STRING EX... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Empty(Exception):
pass
class ArrayStack(object):
def __init__(self):
self._data = []
def __len__(self):
return len(self._data)
def push(self, item):
self._data.append(item)
def is_empty(self):
return len(self._data) == 0
def top(self):
if self... | CLASS_DEF VAR CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR STRING RETURN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balance_check(s):
if len(s) % 2 != 0:
return "NO"
opening = set("([{")
matching = set([("(", ")"), ("[", "]"), ("{", "}")])
stack = []
for paren in s:
if paren in opening:
stack.append(paren)
elif len(stack) == 0:
return "NO"
else:
... | FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR RETURN ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balanced(t):
li = []
for item in t:
if item == "[" or item == "{" or item == "(":
li.append(item)
elif item == "]":
if len(li) == 0 or li[-1] != "[":
return False
break
else:
del li[-1]
elif item == "... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING RETURN NUMBER VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING RETURN NUMBER VAR NUMBER IF VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER S... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | N = int(input())
for n in range(N):
line = input()
balance = []
try:
for l in line:
if l in "({[":
balance.append(l)
elif l in ")}]":
x = balance.pop()
if l == ")" and x != "(":
raise IndexError
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR IF VAR STRING VAR STRING VAR IF VAR STRING VAR STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_C... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def parChecker(string):
balanced = True
index = 0
stack = []
while index < len(string) and balanced:
if string[index] in "({[":
stack.append(string[index])
elif len(stack) == 0:
balanced = False
else:
top = stack.pop()
if not matche... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ST... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | test_cases = int(input())
for _ in range(test_cases):
line = input()
stack = []
cs = []
opened = []
invalid = False
for c in line:
if c == "{":
opened.append(c)
stack.append(c)
elif c == "(":
opened.append(c)
stack.append(c)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input())
while T > 0:
s = input()
stack = []
for ch in s:
if ch in "{[(":
stack.append(ch)
elif len(stack) == 0:
print("NO")
break
elif ch == ")" and stack.pop() != "(":
print("NO")
break
elif ch == "}" and s... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRIN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
ls = []
msg = ""
for i in range(n):
s = input()
msg = ""
ls = []
for c in s:
if c == "(" or c == "[" or c == "{":
ls.append(c)
else:
if len(ls) == 0:
msg = "NO"
break
ch = ls.pop()
if (
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR ST... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def is_pair(parentheses, opening, closing):
return any(x[0] == opening and x[1] == closing for x in parentheses)
T = int(input().strip())
parentheses = [["{", "}"], ["[", "]"], ["(", ")"]]
for i in range(T):
parenthesis = input().strip()
list = []
balanced = True
for character in parenthesis:
... | FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST STRING STRING LIST STRING STRING LIST STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | n = int(input())
strings = []
while n > 0:
strings.append(input())
n -= 1
def check_balanced(string):
s = []
try:
for p in list(string):
if p in ["(", "{", "["]:
s.append(p)
elif p == ")":
if s.pop() != "(":
return Fal... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR STRING RETURN NUMBER IF VAR STRING IF FUNC_CALL VAR STRING RETURN ... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | t = int(input())
while t:
ar = ["e"]
s = input()
for i in s:
if i == "(":
ar.append("(")
elif i == "[":
ar.append("[")
elif i == "{":
ar.append("{")
elif i == ")":
k = ar.pop()
if k != "(":
ar.append(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR LIST STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRIN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def is_balanced(s):
stack = []
for c in s:
if c in ("{", "[", "("):
stack.append(c)
else:
if len(stack) == 0:
return False
o_c = stack.pop()
if (o_c, c) not in (("[", "]"), ("{", "}"), ("(", ")")):
return False
r... | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR STRING STRING STRING STRING STRING STRING RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | open_brackets = "{,[,("
def get_reversed(bracket):
if bracket == "{":
return "}"
elif bracket == "(":
return ")"
elif bracket == "[":
return "]"
def bracket_tes(inp, brackets_stack):
for each in inp:
if each in open_brackets:
brackets_stack.append(each)
... | ASSIGN VAR STRING FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING FUNC_DEF FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBE... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Stack:
def __init__(self, data=None):
self.data = data
if self.data is None:
self.data = []
def push(self, data):
self.data.append(data)
def pop(self):
if len(self.data) > 0:
return self.data.pop()
else:
return None
de... | CLASS_DEF FUNC_DEF NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR RETURN NONE FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING S... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | match = {"}": "{", "]": "[", ")": "("}
def isBalanced(S):
stack = []
for c in S:
if c in "{[(":
stack.append(c)
elif not stack or match[c] != stack.pop():
return False
return not stack
for _ in range(int(input())):
if isBalanced(input()):
print("YES")
... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Stack:
def __init__(self):
self._storage = []
def push(self, data):
self._storage.append(data)
def pop(self):
return self._storage.pop()
def is_empty(self):
return len(self._storage) == 0
def __str__(self):
return self._storage.__str__()
n = int(i... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | T = int(input())
for i in range(T):
stack = []
expression = input()
balanced = "YES"
for j in expression:
if j == "[" or j == "{" or j == "(":
stack.append(j)
elif not stack:
balanced = "NO"
break
else:
val = stack.pop()
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | import sys
STARTING_S = ["(", "[", "{"]
ENDING_S = [")", "]", "}"]
def check_balance(line):
stack = []
for c in line:
if c in STARTING_S:
stack.append(c)
elif c in ENDING_S:
if not stack:
return "NO"
start = stack.pop()
if ENDING... | IMPORT ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR IF VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING RETURN VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CAL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balance(expr):
opens = "{[("
closes = "}])"
s = []
balanced = 0
for i in expr:
if i in opens:
s.append(i)
balanced = 0
continue
else:
if s == []:
return "NO"
if opens.index(s[-1]) == closes.index(i):
... | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR LIST RETURN STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR RETURN STRING IF VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CAL... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | _OPENING_BRACKETS = ["{", "(", "["]
_CLOSING_BRACKETS = ["}", ")", "]"]
def is_seq_correct(seq):
if len(seq) % 2:
return False
opening_seq = list()
it = 0
for x in seq:
if x in _OPENING_BRACKETS:
opening_seq.append(_OPENING_BRACKETS.index(x))
elif x in _CLOSING_BRAC... | ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER EXP... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def check_closer(c, opener, stack_c, other_openers, last_seen):
if last_seen in other_openers:
return False, False
elif len(stack_c) > 0:
stack_c.pop()
return stack_c, c
else:
return False, False
def runme():
closers = [")", "]", "}"]
for i in range(int(input())):
... | FUNC_DEF IF VAR VAR RETURN NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR VAR RETURN NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR IF VA... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | opening = ["{", "[", "("]
closing = ["}", "]", ")"]
def isMatch(a, b):
if a == "{":
if b == "}":
return True
else:
return False
elif a == "[":
if b == "]":
return True
else:
return False
elif a == "(":
if b == ")":
... | ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING FUNC_DEF IF VAR STRING IF VAR STRING RETURN NUMBER RETURN NUMBER IF VAR STRING IF VAR STRING RETURN NUMBER RETURN NUMBER IF VAR STRING IF VAR STRING RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FU... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | class Stack:
def __init__(self):
self.items = []
def push(self, what):
self.items.append(what)
def pop(self, what):
if not self.items:
return False
if (
what == ")"
and self.items[-1] == "("
or what == "]"
and sel... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING V... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balanced_parentheses(s):
openings = "{[("
endings = "}])"
matches = {"}": "{", "]": "[", ")": "("}
stack = []
for i, c in enumerate(s):
if c in openings:
stack.append(c)
elif c in endings and stack and stack[-1] == matches[c]:
stack.pop()
else:
... | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def isMatch(a, b):
if a == "{" and b == "}" or a == "[" and b == "]" or a == "(" and b == ")":
return True
else:
return False
linesToRead = int(input())
linesRead = 0
for i in range(linesToRead):
line = input()
stack = []
result = ""
for token in line:
if token in "{(["... | FUNC_DEF IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NU... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | num_input = input()
for x in range(int(num_input)):
paren = input()
stack = []
balance = "YES"
for c in paren:
if c == ")" or c == "]" or c == "}":
if not stack:
balance = "NO"
else:
opposite = stack.pop()
if c == ")" and op... | ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING IF VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRIN... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | testcases = int(input().strip())
for test in range(testcases):
s = input().strip()
stack = []
processed = 0
for c in s:
processed += 1
if c in "{[(":
stack.append(c)
elif c in "}])" and stack:
match = stack.pop()
if (
match == "... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR... |
A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [... | def balanced(p):
opening = set("({[")
match = set([("(", ")"), ("[", "]"), ("{", "}")])
stack = []
for c in p:
if c in opening:
stack.append(c)
else:
if len(stack) == 0:
return False
last = stack.pop()
if (last, c) not in ma... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR ... |
Given a boolean 2D matrix grid of size n * m. You have to find the number of distinct islands where a group of connected 1s (horizontally or vertically) forms an island. Two islands are considered to be distinct if and only if one island is not equal to another (not rotated or reflected).
Example 1:
Input:
grid[][] = {... | import sys
sys.setrecursionlimit(10**7)
class Solution:
def countDistinctIslands(self, grid) -> int:
def dfs(i, j, si, sj):
if 0 <= i < len(grid) and 0 <= j < len(grid[0]) and grid[i][j] == 1:
grid[i][j] *= -1
isl.append((i - si, j - sj))
dirs... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
lis = adj
d = {}
count = 0
l = [-1] * V
for i in range(0, V):
d[i] = []
for j in range(0, V):
if i != j and adj[i][j] == 1:
d[i].append(j)
def fun(starting, l... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def dfs(self, x, adj, vis):
vis[x] += 1
for i in range(len(adj)):
if adj[x][i] == 1:
if vis[i] == 0:
self.dfs(i, adj, vis)
def numProvinces(self, adj, V):
ans = 0
vis = [0] * V
for i in range(V):
... | CLASS_DEF FUNC_DEF VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.