#### Category : recursion

Good evening I have been writing some python code for my numerical methods course, and I’m getting very bad results from the last section, leading to the message "RuntimeWarning: invalid value encountered in double_scalars". Basically, what the code wants to do is A) Define a couple fields ( T, phi) ; B) Define a matrix ..

I wanted to get permutations of a list of numbers without using any external library. I have written the code below class Solution: def permute(self, nums: List[int] , s = 0 , ans = [] ) -> List[List[int] ]: l = len(nums) if l == 0: return 0 if l == 1: return [nums] if ..

I was solving question of merging two binary trees in LeetCode using recursion but recursion is not working. But recursion is not working in my code.I want to know where I am making mistake. class Solution: def merge(self, root1, root2): if root1 != None and root2 != None: root1.val += root2.val if root1 == None ..

I have been running into an issue when calling a flask api in parallel (problem occurs with only 2 instances). In my full code, I request data from a table and then create a json tree that will then be displayed on the front-end. I noticed that my trees were looking strange, the first one ..

I’m trying to parse a nested JSON in order to insert values into SQL table where the keys would be column names. Here’s a sample of my data: json = {‘inquiry_date’: ‘2021-01-14’, ‘address’: {‘city’: ‘Warsaw’, ‘zip_code’: ’20-200′, ‘country’: ‘Poland’, ‘house_no’: ’22’, ‘street’: ‘Some-Street’}, ‘insert_date’: ‘2020-12-20’, ‘is_active’: False} and here’s parsing function: def parse_json(json): for k, ..

I’m trying to write a code for solving sudoku puzzles, which takes a 9×9 NumPy array as input, and returns a 9×9 NumPy array as output. This is my code: def possible(x,y,n, matris): for i in range(0, 9): if matris[x][i] == n: return False for i in range(0, 9): if matris[i][y] == n: return False ..

I am working on a self-defined class to solve the problem, which is pretty common format in leetcode. The problem is as: Path with Maximum Sum (hard) # Find the path with the maximum sum in a given binary tree. Write a function that returns the maximum sum. A path can be defined as a ..