description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | N = int(input())
A = [int(x) for x in input().split()]
height = [10**7]
count = [1]
paths = 0
for h in A:
while h > height[-1]:
height.pop()
count.pop()
if h == height[-1]:
paths += count[-1]
count[-1] += 1
else:
height.append(h)
count.append(1)
print(2 * path... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR E... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | import sys
def run(hs):
n = 0
cs = []
for h in hs:
while cs and cs[-1][0] < h:
cs.pop()
if cs and cs[-1][0] == h:
n += cs[-1][1]
cs[-1][1] += 1
else:
cs.append([h, 1])
return n * 2
def main():
n = input().strip().split(" ")
... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | import sys
heights = [int(x) for x in sys.stdin.readlines()[1].split()]
class Node:
def __init__(self, value, frequency=1):
self.value, self.frequency = value, frequency
maxes, count = [], 0
for height in heights:
while len(maxes) > 0 and maxes[-1].value < height:
maxes.pop()
if len(ma... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR F... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | N = int(input())
a = list(map(int, input().split()))
res = 0
stack = [(a[0], 1)]
for value in a[1:]:
count = 1
while stack and value >= stack[-1][0]:
prev_value, prev_count = stack.pop()
if prev_value == value:
count += prev_count
else:
res += prev_count * (prev_c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBE... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | READ_FROM_FILE = False
if READ_FROM_FILE:
inp = open("input.txt").readline
else:
inp = input
n = int(inp().strip())
skyscrapers = list(map(int, inp().strip().split()))
paths_count = 0
size = 0
heights = [0] * n
amounts = [0] * n
for skyscraper in skyscrapers:
while size > 0 and heights[size - 1] < skyscrape... | ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR WHILE ... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | L = {}
lines, nums, types = input(), list(map(int, input().split(" "))), []
for i in nums:
if not i in L.keys():
L[i] = [0]
L[i][-1] += 1
while len(types) != 0 and types[-1] < i:
L[types[-1]] += [0]
del types[-1]
if len(types) == 0 or i < types[-1]:
types += [i]
total = 0... | ASSIGN VAR DICT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING LIST FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER LIST NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR N... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | class Stack:
def __init__(self):
self.items = []
def isEmpty(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[len(self.items) - 1]
def size(self):
... | 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 BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR ... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | n = int(input())
heights = list(map(int, input().split(" ")))
answer = 0
routes = []
cur_heights = {}
for a in heights:
if len(routes) == 0:
routes.append(a)
cur_heights[a] = 1
elif routes[0] >= a:
while routes[-1] < a:
cur_heights[routes.pop()] -= 1
routes.append(a)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR WHILE VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR FUN... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | N = int(input())
heights = [int(x) for x in input().split()]
assert len(heights) == N
stack = []
result = 0
for h in heights:
while len(stack) > 0 and stack[-1][0] < h:
stack.pop()
if len(stack) > 0 and stack[-1][0] == h:
result += stack[-1][1]
stack[-1] = stack[-1][0], stack[-1][1] + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR N... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | class Node:
def __init__(self, height=None, count=1, nodeAbove=None):
self.h = height
self.n = count
self.up = nodeAbove
class ArrLinkedLists:
def __init__(self):
self.arr = [None] * 1001
self.lowest = 1001
def eat(self, h):
iArr = h // 1000
if iA... | CLASS_DEF FUNC_DEF NONE NUMBER NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIG... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | def getans(a, v):
le = -1
lc = 0
ans = 0
while len(a) > 0 and a[-1] < v:
e = a.pop()
if e == le:
lc += 1
else:
if lc > 1:
ans += lc * (lc - 1)
le = e
lc = 1
if lc > 1:
ans += lc * (lc - 1)
return ans
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR F... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | N = int(input().strip())
scrapers = [int(num) for num in input().strip().split()]
def unwind(stack, scraper):
flights = 0
current = stack.pop()
times = 1
while len(stack) > 0:
if stack[-1] >= scraper:
flights += times * (times - 1)
stack.append(scraper)
retu... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR IF VAR NUMBER VAR ... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | input()
heights = list(map(int, input().split()))
hs = [9**9] * 300000
ns = [0] * 300000
i = 0
count = 0
for height in heights:
while height > hs[i]:
i -= 1
if height < hs[i]:
i += 1
hs[i] = height
ns[i] = 1
else:
count += ns[i]
ns[i] += 1
print(2 * count) | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VA... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | n = int(input())
height = list(map(int, input().split()))
ans = 0
seen = []
times = {}
for i in height:
if len(seen) == 0:
seen.append(i)
times[i] = 1
elif seen[len(seen) - 1] == i:
times[i] += 1
elif seen[len(seen) - 1] > i:
seen.append(i)
if i in times:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CA... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | class Interval:
def __init__(self, start, end, number, count):
self.start = start
self.end = end
self.number = number
self.count = count
self.parent = None
self.left = None
self.right = None
def __str__(self):
return "({0}, {1}, {2}, {3})".format... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF RETURN FUNC_CALL STRING VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER NO... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | import sys
def getPathsNum(heights):
current_result = {"num": 1, "path_num": 0, "pos": 0}
result_stack = []
i = 1
while i < len(heights):
if heights[i] == heights[current_result["pos"]]:
current_result["num"] = current_result["num"] + 1
i = i + 1
elif heights[i]... | IMPORT FUNC_DEF ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR STRING BIN_OP VAR STRING NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING ... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | def countTot(di):
count = 0
for k, v in di.items():
count += v * (v - 1)
return count
n = int(input())
arr = list(map(int, input().strip().split(" ")))
stack = []
di = {}
tot = 0
for a in arr:
while len(stack) > 0 and stack[-1] < a:
z = stack.pop()
if z not in di:
d... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUM... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | n = int(input().strip())
m = 1000000
h = list(map(int, input().strip().split()))
h.append(m + 1)
r = [0] * n
for i in range(n - 1, -1, -1):
t = i + 1
while h[i] >= h[t]:
t = r[t]
r[i] = t
f = []
for i in range(m + 1):
f.append([])
for i in range(n):
f[h[i]].append(i)
ans = 0
for i in range(m... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR ... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | N = int(input())
arr = list(map(int, input().split()))
ans = 0
ma = [(10**9, 1)]
for i in range(len(arr) - 1, -1, -1):
if arr[i] < ma[-1][0]:
ma.append((arr[i], 1))
else:
while arr[i] > ma[-1][0]:
ma.pop(-1)
if arr[i] == ma[-1][0]:
c, v = ma.pop(-1)
an... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUM... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | import sys
def solution(arr):
res = 0
st = []
for ind in range(len(arr)):
while st and st[-1][0] < arr[ind]:
st.pop()
if st and arr[ind] == st[-1][0]:
res += st[-1][1]
st[-1][1] += 1
else:
st.append([arr[ind], 1])
return 2 * res
... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_C... |
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h... | HEIGHT = "height"
COUNT = "count"
def compute_num_paths(heights):
total_paths = 0
height_stack = []
for i in heights:
while len(height_stack) and height_stack[-1][HEIGHT] < i:
count = height_stack.pop()[COUNT]
total_paths += count * (count - 1)
if len(height_stack) ... | ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR DICT VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER V... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
self.remove(key, root)
def remove(self, word, node, depth=0):
if not node:
return None
if depth == len(word):
return self.getUpdatedLastNodeOfRemovedWord(node)
else:
index = self.getIndexForLett... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF NUMBER IF VAR RETURN NONE IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NONE RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL V... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
curr = root
for c in key:
idx = ord(c) - ord("a")
if curr.children[idx] != None:
curr = curr.children[idx]
curr.isEndOfWord = False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
node = root
for i in key:
count = 0
for j in node.children:
if j is None:
count += 1
ind = ord(i) - ord("a")
if count < 25:
node = node.children[ind]
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NONE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NONE ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
def empty(n):
for i in range(26):
if n.children[i]:
return False
return True
def remove(n, key, i):
if i == len(key):
n.isEndOfWord = False
retur... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NONE RETURN NUMBE... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def _isEmpty(self, root):
for child in root.children:
if child != None:
return False
return True
def deleteKey(self, root, key):
cur = root
for c in key:
idx = ord(c) - ord("a")
cur = cur.children[idx]
... | CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR NONE RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR IF VAR NONE RETURN ASSIGN VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR STRING VAR IF VAR NONE RETURN NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL ... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
def delete(word, pos, root):
if not root:
return
if pos == len(word):
if root.isEndOfWord:
root.isEndOfWord = False
return
delete(word, pos + 1, root.... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN IF VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
length = len(key)
def search(root, key):
currentNode = root
for i in range(length):
index = ord(key[i]) - ord("a")
if currentNode.children[index] is None:
return False
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR NONE RETURN NUMBER ASSIGN VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
curr = root
for l in key:
idx = charToIndex(l)
if not curr.children[idx]:
return
curr = curr.children[idx]
curr.isEndOfWord = False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def _deleteKey(self, root, key, index):
if not root or index >= len(key):
return
newRoot = root.children[charToIndex(key[index])]
self._deleteKey(newRoot, key, index + 1)
if index == len(key) - 1 and newRoot.isEndOfWord:
newRoot.isEndOfWord = ... | CLASS_DEF FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NONE FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
for i in range(len(key)):
if root.children[ord(key[i]) - ord("a")] != None:
root = root.children[ord(key[i]) - ord("a")]
root.isEndOfWord = False | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NONE ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
curr = root
for ele in key:
if not curr.children[ord(ele) - ord("a")]:
return
curr = curr.children[ord(ele) - ord("a")]
curr.isEndOfWord = False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def cti(self, c: str):
return ord(c) - ord("a")
def deleteKey(self, root, key):
for c in key:
index = self.cti(c)
if not root.children[index]:
return
root = root.children[index]
root.isEndOfWord = False | CLASS_DEF FUNC_DEF VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
a = ord("a")
for i in key:
if root.children[ord(i) - a] == None:
return False
root = root.children[ord(i) - a]
if root.isEndOfWord == False:
return 0
root.isEndOfWord = False
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NONE RETURN NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER RETURN NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | def c2i(s):
return ord(s) - ord("a")
class Solution:
def deleteKey(self, root, key):
pCrawl = root
length = len(key)
for level in range(length):
index = c2i(key[level])
if pCrawl.children[index] is None:
return
pCrawl = pCrawl.childr... | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NONE RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER CLAS... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey1(self, root, key):
temp = root
for ch in key:
idx = ord(ch) - ord("a")
temp = temp.children[idx]
if temp is None:
return
temp.isEndOfWord = False
def has_child(self, root):
for i, child in enumera... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR IF VAR NONE RETURN ASSIGN VAR NUMBER FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR IF VAR NONE RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VA... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, word):
temp = root
n = len(word)
for i in range(n):
idx = ord(word[i]) - 97
if not temp.children[idx]:
return
temp = temp.children[idx]
temp.isEndOfWord = 0 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def is_empty(self, root):
for i in range(26):
if root.children[i]:
return False
return True
def deleteKey(self, root, key, depth=0):
try:
if root is None:
return
if len(key) == depth:
if... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF NUMBER IF VAR NONE RETURN IF FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VA... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def delete(self, node, s, i):
if i == len(s):
if node.isEndOfWord == True:
node.isEndOfWord = False
return
self.delete(node.children[ord(s[i]) - 97], s, i + 1)
x = 0
for j in node.children:
if j != None:
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NONE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NONE RETURN FUNC_DEF EXPR FUNC_CALL VAR VA... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
def delete(i, key, root):
if i == len(key) and root.isEndOfWord:
root.isEndOfWord = False
return root.children
idx = ord(key[i]) - ord("a")
if root.children[idx]:
root = dele... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR NUMBER VAR VAR |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
depth = 0
self.delete(root, key, depth)
def delete(self, root, key, depth):
if root == None:
return None
if len(key) == depth:
if root.isEndOfWord == True:
root.isEndOfWord = False
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NONE RETURN NONE IF FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR N... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | def chartoindex(s):
return ord(s) - ord("a")
class Solution:
def deleteKey(self, root, key):
curr = root
for c in key:
idx = chartoindex(c)
if curr.children[idx]:
curr = curr.children[idx]
curr.isEndOfWord = False | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
if len(key) == 0:
if root.isEndOfWord:
root.isEndOfWord = False
return True
return False
index = ord(key[0]) - ord("a")
if root.children[index] is not None:
child = root.child... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR VAR NONE ASSIGN VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
def isEmpty(r):
for c in r.children:
if c:
return False
return True
def deleteK(r, k, depth):
if not r:
return None
if depth == len(k):
... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR VAR IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR RETURN NONE IF VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
if root != None:
if len(key) == 0:
root.isEndOfWord = 0
else:
self.deleteKey(root.children[ord(key[0]) - 97], key[1:]) | CLASS_DEF FUNC_DEF IF VAR NONE IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | def idx(c):
return ord(c) - ord("a")
def child_count(node):
return sum(1 for child in node.children if child)
class Solution:
def deleteKey(self, root, key):
last_node = root, idx(key[0])
node = root
for c in key:
i = idx(c)
if child_count(node) > 1:
... | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR NUMBER VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NONE RETURN ASSIGN VA... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
ki = 0
ke = len(key)
snode = []
while root and root.isEndOfWord == False:
v = charToIndex(key[ki])
if root.children[v]:
snode.append([root, v])
root = root.children[v]
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR FOR VAR VAR ASSIGN VAR NUMBER VAR NUMBER NONE ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR A... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
n = len(key)
cur = root
stacks = [cur]
for i in range(n):
idx = charToIndex(key[i])
if cur.children[idx] is None:
return
else:
cur = cur.children[idx]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NONE RETURN ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NONE VAR NUMBER IF VAR NUM... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
temp = root
for ch in key:
idx = ord(ch) - ord("a")
temp = temp.children[idx]
if temp is None:
return
temp.isEndOfWord = False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR IF VAR NONE RETURN ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
temp = root
level = 0
if search(root, key):
while level < len(key) and temp.children[ord(key[level]) - 97]:
temp = temp.children[ord(key[level]) - 97]
level += 1
temp.isEndOfWord = False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
if not search(root, key):
return
curr = root
for w in key:
idx = ord(w) - ord("a")
if curr.children[idx] is None:
return False
curr = curr.children[idx]
if curr.isEndOfWor... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR NONE RETURN NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, word):
ROOT = root
stack = []
for w in word:
index = ord(w) - ord("a")
if not root.children[index]:
return False
stack.append(root)
root = root.children[index]
if any(root.child... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR N... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def _util(self, root, key, i):
if not root:
return None
if i == len(key):
root.isEndOfWord = False
if self.isEmpty(root):
root = None
return root
index = charToIndex(key[i])
root.children[index] = self._... | CLASS_DEF FUNC_DEF IF VAR RETURN NONE IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NONE FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NO... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
return self.deleteUtil(root, key, 0)
def deleteUtil(self, root, word, depth):
if root is None:
return None
if depth == len(word):
if root.isEndOfWord == True:
root.isEndOfWord = False
is... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN NONE IF VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NONE ASSIGN VAR NUMBER IF VAR ASSIGN VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP ... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
if len(key) == 0:
root.isEndOfWord = False
return
index = ord(key[0]) - ord("a")
if root.children[index]:
self.deleteKey(root.children[index], key[1:]) | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
self.dele(root, key, 0)
def dele(self, root, key, i):
if i == len(key):
return
index = ord(key[i]) - ord("a")
if not root.children[index]:
return
self.dele(root.children[index], key, i + 1)
... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
r = root
cnt = 1
for i in key:
if r.children[ord(i) - ord("a")] == None:
return root
if cnt == len(key):
if r.children[ord(i) - ord("a")].isEndOfWord:
r.children[ord(i... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NONE RETURN VAR IF VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_... |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def deleteKey(self, root, key):
if search(root, key):
pcrawl = root
length = len(key)
for level in range(length):
index = charToIndex(key[level])
pcrawl = pcrawl.children[index]
pcrawl.isEndOfWord = False | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER |
Trie is an efficient information retrieval data structure. This data structure is used to store Strings and search strings, String stored can also be deleted. Given a Trie root for a larger string super and a string key, delete all the occurences of key in the Trie.
Example 1:
Input:
N = 8
super = "the a there answer a... | class Solution:
def delete(self, CurrNode, key, pos):
if CurrNode == None:
return
if pos == len(key):
CurrNode.isEndOfWord = False
return
self.delete(CurrNode.children[ord(key[pos]) - ord("a")], key, pos + 1)
def deleteKey(self, root, key):
s... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR VAR NUMBER |
You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i.
At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements p_1, p_2, ... , ... | import sys
def main():
import sys
input = sys.stdin.buffer.readline
N = int(input())
P = list(map(int, input().split()))
A = list(map(float, input().split()))
class LazySegTree:
def __init__(self, A, initialize=True, segfunc=min, ident=2000000000):
self.N = len(A)
... | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR NUMBER ASSI... |
You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i.
At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements p_1, p_2, ... , ... | import sys
from itertools import accumulate
input = sys.stdin.readline
n = int(input())
P = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
seg_el = 1 << (n + 1).bit_length()
SEGMIN = [0] * (2 * seg_el)
SEGADD = [0] * (2 * seg_el)
for i in range(n):
SEGMIN[P[i] + seg_el] = A[i]
SEGMIN = list(... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST N... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def Search(start, end, value, inorder):
for indx in range(start, end + 1):
if value == inorder[indx]:
return indx
return -1
def BuildTree(In, post, postindx, instart, inend):
if instart > inend:
return None
if postindx[0] < 0:
return None
root = Node(post[postin... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NONE IF VAR NUMBER NUMBER RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMB... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(io, po, n):
if len(io) != len(po):
return None
def util(d, io, io1, io2, po, po1, po2):
if io1 > io2 or po1 > po2:
return None
root = Node(po[po2])
ind = d[po[po2]]
if io1 != io2:
root.left = util(d, io, io1, ind - 1, po, po1, po1 + ... | FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NONE FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n=None):
if not In or not post:
return None
root_value = post[-1]
root = Node(root_value)
root_index = In.index(root_value)
if n is None:
n = len(In)
leftsize = root_index
rightsize = n - root_index - 1
root.left = buildTree(In[:root_index], post[:... | FUNC_DEF NONE IF VAR VAR RETURN NONE ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def build(ino, post, h, ind, i, j):
if i > j:
return None
root = Node(post[ind[0]])
ind[0] -= 1
if i == j:
return root
root.right = build(ino, post, h, ind, h[root.data] + 1, j)
root.left = build(ino, post, h, ind, i, h[root.data] - 1)
return root
def buildTree(ino, post, n... | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR F... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
inomap = {}
for i, el in enumerate(inorder):
inomap[el] = i
def get_tree(isi, iei, ppsi, ppei):
if ppei < ppsi:
return None
inidx = inomap[postorder[ppei]]
l = inidx - isi
root = Node(postorder[ppei])
if ppsi ... | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_O... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
i = [n - 1]
mydict = {}
for j in range(n):
mydict[In[j]] = j
def construct(start, end):
if start > end:
return None
root = Node(post[i[0]])
i[0] -= 1
if start == end:
return root
middle = mydict[root.dat... | FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_O... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def _buildtree(postorder, poststart, postend, inorder, instart, inend, hashmap):
if instart > inend or poststart > postend:
return None
root = Node(postorder[postend])
inroot = hashmap[postorder[postend]]
numsleft = inroot - instart
root.left = _buildtree(
postorder,
poststar... | FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUN... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
postorder = postorder[::-1]
def sol(post, ino):
if not post and not ino:
return None
mid_val = ino.index(post[0])
root = Node(post[0])
root.left = sol(post[len(post) - mid_val :], ino[:mid_val])
root.right = sol(post[1 : ... | FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
poststart = instart = 0
postend = inend = n - 1
return constructTree(post, poststart, postend, In, instart, inend)
def search(In, instart, inend, val):
for i in range(instart, inend + 1):
if In[i] == val:
return i
def constructTree(post, poststart, pos... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
inorderMap = {}
for i, e in enumerate(In):
inorderMap[e] = i
i = n - 1
def buildTreeUtil(l, r):
nonlocal i, inorderMap
if l >= r:
return None
else:
n = Node(post[i])
i -= 1
n.right = buildTreeUti... | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR NUMBER VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | import sys
def buildTree(inorder, postorder, n):
inMap = {}
import sys
sys.setrecursionlimit(1000000)
for i, num in enumerate(inorder):
if inMap.get(num, sys.maxsize) == sys.maxsize:
inMap[num] = [i]
else:
inMap[num].append(i)
return buildTreeUtil(
... | IMPORT FUNC_DEF ASSIGN VAR DICT IMPORT EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF IF VAR VAR VAR VAR RETURN... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(ino, post, n):
if not ino or not post:
return None
root = Node(post[-1])
m = post.index(root.data)
k = ino.index(root.data)
root.left = buildTree(ino[:k], post[:k], n)
root.right = buildTree(ino[k + 1 :], post[k:m], n)
return root | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def build(In, s1, e1, post, s2, e2):
if s1 > e1:
return None
node = Node(post[e2])
idx = In.index(post[e2])
node.left = build(In, s1, idx - 1, post, s2, idx - 1 - s1 + s2)
node.right = build(In, idx + 1, e1, post, e2 - e1 + idx, e2 - 1)
return node
def buildTree(In, post, n):
retur... | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETU... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
def buildtree(ino, ist, ied, pos, pst, ped, mp):
if ist > ied or pst > ped:
return None
root = Node(pos[ped])
inroot = mp[root.data]
numsleft = inroot - ist
root.left = buildtree(ino, ist, inroot - 1, pos, pst, pst + numsleft - 1, mp)
... | FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN VA... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
inorderidx = {v: i for i, v in enumerate(In)}
def helper(l, r):
if l > r:
return None
root = Node(post.pop())
idx = inorderidx[root.data]
root.right = helper(idx + 1, r)
root.left = helper(l, idx - 1)
return root
retur... | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
d = {}
for i in range(n):
if In[i] in d:
d[In[i]].append(i)
else:
d[In[i]] = [i]
def helper(inorder, postorder, li, ri, lp, rp):
if li > ri or lp > rp:
return None
root = Node(postorder[rp])
indices = d[... | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR F... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if not In or not post:
return None
root = Node(post[n - 1])
index = In.index(post[n - 1])
root.left = buildTree(In[:index], post[:index], len(post[:index]))
root.right = buildTree(
In[index + 1 :], post[index : n - 1], len(post[index : n - 1])
)
re... | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | pind = 0
def buildTree(inorder, postorder, n=8):
if not inorder or not postorder:
return None
root_val = postorder[-1]
root = Node(root_val)
idx = inorder.index(root_val)
root.left = buildTree(inorder[:idx], postorder[:idx])
root.right = buildTree(inorder[idx + 1 :], postorder[idx:-1])... | ASSIGN VAR NUMBER FUNC_DEF NUMBER IF VAR VAR RETURN NONE ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if not In or not post:
return None
idx = In.index(post[-1])
root = Node(post.pop())
root.right = buildTree(In[idx + 1 :], post, n)
root.left = buildTree(In[:idx], post, n)
return root | FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def build(inorder, postorder, start_in, end_in, start_post, end_post, dic):
if start_post > end_post or start_in > end_in:
return None
root = Node(postorder[end_post])
index_root = [x for x in dic[root.data] if start_in <= x <= end_in]
num_left = index_root[0] - start_in
root.left = build(
... | FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
return helper(0, n - 1, post, In, n - 1)[0]
def helper(start, stop, post, In, p):
if p < 0:
return None, -1
if start > stop:
return None, p
for i in range(start, stop + 1):
if post[p] == In[i]:
right, p = helper(i + 1, stop, post, In, p -... | FUNC_DEF RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NONE NUMBER IF VAR VAR RETURN NONE VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CAL... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
if inorder == None or len(inorder) != len(postorder):
return None
a = {}
for i in range(len(inorder)):
a[inorder[i]] = i
def createTree(inorder, ip, ie, postorder, pp, pe, a):
root = Node(postorder[pe])
if pp > pe or ip >... | FUNC_DEF IF VAR NONE FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NONE ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if not In or not post:
return
index = In.index(post[-1])
root = Node(post[-1])
root.left = buildTree(In[0:index], post[0:index], n)
root.right = buildTree(In[index + 1 :], post[index:-1], n)
return root | FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
global postindex
postindex = n - 1
def SearchArray(arr, start, end, value):
for i in range(start, end + 1):
if arr[i] == value:
return i
return -1
def BuildTree_IPos(inOrder, postOrder, instart, inend):
global postindex
... | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def find(inorder, post, instart, inend):
if instart > inend:
return
root = Node(post[find.postindex])
find.postindex -= 1
for i in range(instart, inend + 1):
if inorder[i] == root.data:
break
root.right = find(inorder, post, i + 1, inend)
root.left = find(inorder, pos... | FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NU... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
root = post[-1]
rootNode = Node(root)
rootIndex = In.index(root)
if In[0:rootIndex]:
rootNode.left = buildTree(In[0:rootIndex], post[0:rootIndex], rootIndex)
if In[rootIndex + 1 :]:
rootNode.right = buildTree(
In[rootIndex + 1 :], post[rootInde... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if n <= 0:
return None
root = Node(post[n - 1])
for i in range(n):
if In[i] == post[n - 1]:
break
root.left = buildTree(In, post, i)
root.right = buildTree(In[i + 1 :], post[i:], n - i - 1)
return root | FUNC_DEF IF VAR NUMBER RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
def recursive(In, post, idx=n - 1, lo=0, hi=n - 1):
if idx < 0:
return None, idx
cur = post[idx]
root = None
for i in range(lo, hi + 1):
if In[i] == cur:
root = Node(cur)
break
if root:
... | FUNC_DEF FUNC_DEF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN NONE VAR ASSIGN VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CA... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
def dum(In, post):
if not In:
return None
p = post.pop()
root = Node(p)
i = In.index(p)
root.right = dum(In[i + 1 :], post)
root.left = dum(In[:i], post)
return root
return dum(In, post) | FUNC_DEF FUNC_DEF IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
post_idx = [n - 1]
return buildUtil(In, 0, n - 1, post, post_idx)
def buildUtil(inorder, start, end, postorder, post_idx):
if start > end:
return None
i = post_idx[0]
root = postorder[i]
post_idx[0] -= 1
for idx in range(start, end + 1):
if inord... | FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | mp = {}
def buildTreeUtil(In, post, instart, inend, preIndex):
if instart > inend:
return None
new = Node(post[preIndex[0]])
preIndex[0] -= 1
if instart == inend:
return new
inIndex = mp[new.data]
new.right = buildTreeUtil(In, post, inIndex + 1, inend, preIndex)
new.left = ... | ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VA... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
if n == 0:
return
pos = In.index(post[-1])
node = Node(post[-1])
node.left = buildTree(In[:pos], post[:pos], pos)
node.right = buildTree(In[pos + 1 :], post[pos : n - 1], n - 1 - pos)
return node | FUNC_DEF IF VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(inorder, postorder, n):
def builder(inorder, postorder, in_start, in_end, post_start, post_end):
if in_start > in_end or post_start > post_end:
return None
node = Node(postorder[post_end])
for node_pos in range(in_start, in_end + 1):
if inorder[node_pos... | FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | class Node:
def __init__(self, data):
self.data = data
self.left = self.right = None
def buildTree(In, post, n):
mp = {}
for i in range(n):
if In[i] not in mp:
mp[In[i]] = []
mp[In[i]].append(i)
postS = [n - 1]
inS = 0
inE = n - 1
return solutio... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NONE FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUM... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
return solve(In, post, 0, n - 1, n)
def solve(In, post, start, end, n):
if n == 0:
return None
rootdata = post[n - 1]
root = Node(rootdata)
rootindexin = -1
for i in range(start, end + 1):
if In[i] == rootdata:
rootindexin = i
... | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NONE ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
post_ind = [n - 1]
def build(post=post, io=In, isi=0, iei=n - 1):
if isi > iei:
return None
root = Node(post[post_ind[0]])
post_ind[0] -= 1
if isi == iei:
return root
for i in range(isi, iei + 1):
if io[i] =... | FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER FUNC_DEF VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CA... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def buildTree(In, post, n):
def builder(pi, pj, l, r):
if pj < pi:
return None
root = Node(post[pj])
i = l
while i <= r:
if root.data == In[i]:
break
i += 1
root.right = builder(pj - (r - i), pj - 1, i + 1, r)
root.... | FUNC_DEF FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VA... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | def solve(In, post, post_idx, in_start_idx, in_end_idx, node_map):
if post_idx[0] < 0 or in_start_idx > in_end_idx:
return None
element = post[post_idx[0]]
root = Node(element)
post_idx[0] -= 1
pos = node_map[element]
root.right = solve(In, post, post_idx, pos + 1, in_end_idx, node_map)
... | FUNC_DEF IF VAR NUMBER NUMBER VAR VAR RETURN NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC... |
Given inorder and postorder traversals of a Binary Tree in the arrays in[] and post[] respectively. The task is to construct the binary tree from these traversals.
Example 1:
Input:
N = 8
in[] = 4 8 2 5 1 6 3 7
post[] =8 4 5 2 6 7 3 1
Output: 1 2 4 8 5 3 6 7
Explanation: For the given postorder and
inorder traversal ... | mp = {}
def buildTree(In, post, n):
global post_ind, mp
post_ind = len(post) - 1
def recur(In, post, isi, iei):
if isi > iei:
return None
global post_ind, mp
curr = post[post_ind]
root = Node(curr)
post_ind -= 1
if isi == iei:
return... | ASSIGN VAR DICT FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.