Coding Patterns

1.3) Binary Tree Zigzag Level Order Traversal

Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. Zigzag level order traversal means visiting all nodes at each level alternatively from…

1.1) Binary Tree Level Order Traversal

Given the root of a binary tree, return the level order traversal of its nodes' values. Level order traversal means visiting all nodes at each level from left to right…

Binary Tree Inorder Traversal

Given the root of a binary tree, return the inorder traversal of its nodes' values. In inorder traversal, we visit the left subtree first, then the current node, and finally…

Range Sum of BST

Given the root of a binary search tree (BST), and integers low and high, find the sum of all node values in the BST that are within the range .

Sum Root to Leaf Numbers

Given a binary tree, where each node has a value between 0 and 9, find the total sum of all root-to-leaf numbers. A root-to-leaf number is a number represented by…

Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum. The maximum path sum is defined as the maximum sum of any path from any node to any node in the…

Path Sum III

Given a binary tree and a target sum, find the total number of all paths in the tree such that the sum of the values along the path equals the…

Path Sum II

Given a binary tree and a target sum, find all root-to-leaf paths where each path's sum equals the given target sum. A leaf is a node with no children.

Path Sum

Given a binary tree and a target sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given target…

Middle of the Linked List

Given a singly-linked list, find the middle node of the list. If the list contains an even number of nodes, return the second middle node.