I understand that this could be out of this forum but let me clarify why I have decided to post it here.
I try to submit a code problem but the grader doesn’t accept my result. I can’t see the test case, I see only the error message that states
unknown signal 11 (Time used: 0.81/10.00, memory used: 101203968/536870912.)
I know that in signal #11 in Linux stands for segmentation fault. But I can’t get what’s wrong with my code. Other test cases are run without any problems. So I think that it is mostly design problem.
#!/usr/bin/python3 import sys, threading sys.setrecursionlimit(10**7) # max depth of recursion threading.stack_size(2**25) # new thread will get stack of such size def IsBinarySearchTree(tree): # Implement correct algorithm here min = -sys.maxsize max = sys.maxsize def is_bst_until(idx_node,maxi,mini): if idx_node == -1: return True node = tree[idx_node] key = node idx_left = node idx_right = node #print('max',maxi, "min", mini) if (key>maxi) or (key<mini): #print("False", key, maxi,mini) return False return (is_bst_until(idx_right, maxi, key+1)) and (is_bst_until(idx_left, key-1, mini)) #print(tree) if len(tree) == 0: return True return is_bst_until(0, max, min) def main(): nodes = int(sys.stdin.readline().strip()) tree =  for i in range(nodes): tree.append(list(map(int, sys.stdin.readline().strip().split()))) if IsBinarySearchTree(tree): print("CORRECT") else: print("INCORRECT") threading.Thread(target=main).start()
Input: The first line contains the number of vertices 𝑛. The vertices of the tree are numbered from 0 to 𝑛−1. Vertex 0 is the root. The next 𝑛 lines contain information about vertices 0, 1, …, 𝑛 − 1 in order. Each of these lines contains three integers 𝑘𝑒𝑦𝑖, 𝑙𝑒𝑓𝑡𝑖 and 𝑟𝑖𝑔h𝑡𝑖 — 𝑘𝑒𝑦𝑖 is the key of the 𝑖-th vertex, 𝑙𝑒𝑓𝑡𝑖 is the index of the left child of the 𝑖-th vertex, and 𝑟𝑖𝑔h𝑡𝑖 is the index of the right child of the 𝑖-th vertex. If 𝑖 doesn’t have left or right child (or both), the corresponding 𝑙𝑒𝑓𝑡𝑖 or 𝑟𝑖𝑔h𝑡𝑖 (or both) will be equal to −1.
Output: If the given binary tree is a correct binary search tree (see the definition in the problem description), output one word “CORRECT” (without quotes). Otherwise, output one word “INCOR- RECT” (without quotes).
3 1 1 2 2 -1 -1 3 -1 -1 INCORRECT 3 2 1 2 1 -1 -1 3 -1 -1 CORRECT