All Posts

Leetcode 109: Convert Sorted List to Binary Search Tree

Given the head of a singly linked list where elements are sorted in ascending order, convert it into a height-balanced binary search tree. A height-balanced binary search tree is one where the depth of the two subtrees of every node never differs by more than 1.

Leetcode 114: Flatten Binary Tree to Linked List

Given the root of a binary tree, flatten the tree into a ’linked list’ where each node’s right pointer points to the next node in pre-order traversal, and the left pointer of all nodes is null. The ’linked list’ should maintain the same order as a pre-order traversal of the binary tree.

Leetcode 116: Populating Next Right Pointers in Each Node

You are given a perfect binary tree where every parent node has two children and all leaves are at the same level. Your task is to populate the ’next’ pointer of each node to point to its next right node. If no such node exists, set the ’next’ pointer to NULL. Initially, all ’next’ pointers are set to NULL.

Leetcode 138: Copy List with Random Pointer

Given a linked list where each node contains a value, a next pointer, and a random pointer (which can point to any node in the list or be null), create a deep copy of the list. The deep copy should consist of exactly n new nodes where each node has its value set to the value of its corresponding original node, and the next and random pointers of the new nodes should represent the same list state as the original. None of the pointers in the new list should point to nodes in the original list.

Leetcode 141: Linked List Cycle

Given the head of a linked list, determine if there is a cycle. A cycle occurs if a node can be revisited by following the ’next’ pointers. The ‘pos’ parameter denotes where the last node connects to. If ‘pos’ is -1, there is no cycle.

Leetcode 142: Linked List Cycle II

Given the head of a linked list, find the node where the cycle begins. If no cycle exists, return null. The list may contain a cycle, which occurs if a node can be revisited by following the ’next’ pointers continuously.