Articles
-
Nth to Last Node in List
Find the nth to last element of a singly linked list. The minimum number of nodes in list is n.
-
111 - Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
-
Cosine Similarity
Cosine similarity is a measure of similarity between two vectors of an inner product space that measures the cosine of the angle between them. The cosine of 0° is 1, and it is less than 1 for any other angle.
-
173 - Binary Search Tree Iterator
Design an iterator over a binary search tree with the following rules: Elements are visited in ascending order (i.e. an in-order traversal) next() and hasNext() queries run in O(1) time in average.
-
109 - Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
-
108 - Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
-
11 - Search Range in Binary Search Tree
Given two values k1 and k2 (where k1 <= k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1 <= x <= k2 and x is a key of given BST. Return all the keys in ascending order.
-
98 - Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).
-
103 - Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).
-
106 - Construct Binary Tree from Inorder and Postorder Traversal
Construct a binary tree from inorder and postorder traversal.
-
105 - Construct Binary Tree from Preorder and Inorder Traversal
Construct a binary tree from preorder and inorder traversal.
-
543 - Diameter of a Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.
-
226 - Invert Binary Tree
Invert a binary tree
-
124 - Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree.
-
110 - Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
-
104 - Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
-
107 - Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).
-
102 - Binary Tree Level Order Traversal
Binary tree level order traversal.
-
145 - Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes’ values.
-
94 - Binary Tree Inorder Traversal
Inorder traversal a binary tree
-
144 - Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.
-
138 - Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.
-
148 - Sort List
Sort a linked list in O(n log n) time using constant space complexity.
-
147 - Insertion Sort List
Sort a linked list using insertion sort.
-
234 - Palindrome Linked List
Given a singly linked list of integers, write a function that returns true if the given list is palindrome, else false.
-
143 - Reorder List
Given a singly linked list L: L0 - L1 - … - Ln-1 - Ln, reorder it to: L0 - Ln - L1 - Ln-1 - L2 - Ln-2 - … You must do this in-place without altering the nodes’ values.
-
23 - Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
-
21 - Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
-
92 - Reverse Linked List II
Reverse a linked list from position m to n.
-
206 - Reverse Linked List
Reverse a singly linked list.