testcases: - name: "testcase 1" inputs: - 1 : [6,2,8,0,4,7,9,null,null,3,5] - 2 : 2 - 3 : 8 output: - 1 : 6 - name: "testcase 2" inputs: - 1 : [6,2,8,0,4,7,9,null,null,3,5] - 2 : 2 - 3 : 4 output: - 1 : 2 - name: "testcase 3" inputs: - 1 : [2,1] - 2 : 2 - 3 : 1 output: - 1 : 2 - name: "testcase 4" inputs: - 1 : [2,1,3] - 2 : 1 - 3 : 3 output: - 1 : 2 - name: "testcase 5" inputs: - 1 : [20,8,22,4,12,null,null,null,null,10,14] - 2 : 10 - 3 : 14 output: - 1 : 12 # def validate_inputs(self) -> None: # """ # self.__inputs is the list of inputs that are passed as input to function # store the result using the self.store_result(error_msg, status) # return : void # """ # from ds_v1.BinaryTree.BinaryTree import TreeNode # from collections import deque # def level_order_traversal(root): # if not root: # return [] # result = [] # q = deque([root]) # while q: # curr = q.popleft() # if curr: # result.append(curr.data) # q.append(curr.left) # q.append(curr.right) # else: # result.append(None) # if all(val == None for val in q): # break # return result # def is_valid_level_order(level_order): # if not level_order: # return True # An empty list is a valid level-order traversal # n = len(level_order) # i = 0 # root = TreeNode(level_order[i]) # q = deque([root]) # i = 1 # while i < n and q: # curr = q.popleft() # if level_order[i] is not None: # curr.left = TreeNode(level_order[i]) # q.append(curr.left) # i += 1 # if i < n and level_order[i] is not None: # curr.right = TreeNode(level_order[i]) # q.append(curr.right) # i += 1 # # Remove None values after the last integer # while level_order and level_order[-1] is None: # level_order.pop() # return level_order_traversal(root) == level_order # def has_duplicates(arr): # seen = set() # for element in arr: # if element in seen: # return True # seen.add(element) # return False # # inputs can be accessed using self.__inputs starting from 0 to len(self.__inputs) - 1 # input_list = self.__inputs[0] # p = self.__inputs[1] # q = self.__inputs[2] # # inputs can be accessed using self.__inputs starting from 0 to len(self.__inputs) - 1 # # if not (2 <= sum(1 for value in input_list if value is not None) <= 1000): # # self.store_result ("Total nodes in the tree are expected to be between 2 and 1000", ValidationFunction.FAIL) # # elif has_duplicates(input_list): # # self.store_result ("There should not be duplicates in the tree", ValidationFunction.FAIL) # # elif (len(input_list) !=0 and input_list[0] is None): # # self.store_result ("Not a valid value of type TreeNode", ValidationFunction.FAIL) # # elif (len(input_list) !=0 and input_list[0] is None): # # self.store_result ("Not a valid value of type TreeNode", ValidationFunction.FAIL) # # elif not is_valid_level_order(input_list): # # self.store_result ("Not a valid value of type TreeNode", ValidationFunction.FAIL) # # elif not p in input_list or not q in input_list: # # self.store_result ("'p' and 'q' must exist in the tree", ValidationFunction.FAIL) # # elif p == q: # # self.store_result ("p and q are equal", ValidationFunction.FAIL) # else: # self.store_result("", ValidationFunction.PASS)