## leetcode weekly contest 169

[source to contest page](https://leetcode.com/contest/weekly-contest-169) 5295. Find N Unique Integers Sum up to Zero The code is quite self-explanatory. This is one of the easiest I've seen so far. ```python class Solution: def sumZero(self, n: int) -> List[int]: return [i for i in range(n-1)]+[-sum(range(n-1))] ``` 5296. All Elements in Two Binary Search Trees This can be brute-forced. ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def getAllElements(self, A: TreeNode, B: TreeNode) -> List[int]: l=[] def flat(T): if T: l.append(T.val) flat(T.left) flat(T.right) flat(A) flat(B) return sorted(l) ``` 5297. Jump Game III thought of bunch of ideas, settled on dfs: ```python class Solution: def canReach(self, A: List[int], s: int) -> bool: if A[s]==0: return True n=len(A) Z=[False]*n found=False for i in range(n): if A[i]==0: Z[i]=True found=True if not found: return False R=[False]*n R[s]=True #dfs st=[s] while st: cur=st.pop() r=cur+A[cur] if 0<=r<n: if Z[r]: return True if not R[r]: st.append(r) R[r]=True l=cur-A[cur] if 0<=l<n: if Z[l]: return True if not R[l]: st.append(l) R[l]=True return False ``` And finally, the [last problem](https://leetcode.com/problems/verbal-arithmetic-puzzle/). I solved the first three in 13 minutes and try to pass the given test cases for more than half an hour before I finally gave up. [One way](https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/463886/Python-backtracking-w-Explanation) is to back-track on columns, from right to left, keeping track of current row, current column, and a carry. There are [other backtracking methods](https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/463900/ACCEPTED-Java-Backtracking-Using-an-Int-Array-as-Map-passed-all-test-cases) available but it seems some only works in certain languages. Overall I did okay this time (ranked ~340 / ~5800), the last problem is really hard this time.