Tree

General template for various tree questions. Source

Inorder Traversal ```java public List inorderTraversal(TreeNode root) { List list = new ArrayList<>(); if(root == null) return list; Stack stack = new Stack<>(); while(root != null || !stack.empty()){ while(root != null){ stack.push(root); root = root.left; } root = stack.pop(); list.add(root.val); root = root.right;

}
return list; } ```
Read More

Backtracking

Backtracking recursion

Build up many possible solutions through multiple recursive calls at each step

Seed the initial recursive call with an “empty” solution

At each base case, you have a potential solution

Read More