Skip to main content
109, Convert Sorted List to Binary Search Tree

I Problem

Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Example 1

Input: head = [-10, -3, 0, 5, 9]
Output: [0, -3, 9, -10, null, 5]
Explanation: One possible answer is [0, -3, 9, -10, null, 5], which represents the shown height balanced BST.


MikeAbout 2 minbinary treemediumlinked listbinary treebinary search treedivide and conquer
116, Populating Next Right Pointers in Each Node

I Problem

You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:

struct Node {
    int val;
    Node *left;
    Node *right;
    Node *next;
}

MikeAbout 5 minbinary treemediumbinary treelinked listdepth first searchbreadth first search
142, Linked List Cycle II

I Problem

Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer.
Internally, pos is used to denote the index of the node that tail's next pointer is connected to (0-indexed). It is -1 if there is no cycle.
Note that pos is not passed as a parameter.


MikeAbout 2 minlinkedlistmediumhash tablelinked listtwo pointers
141, Linked List Cycle

I Problem

Given head, the head of a linked list, determine if the linked list has a cycle in it.

There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer.
Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter.


MikeAbout 2 minlinkedlisteasyhash tablelinked listtwo pointers
160, Intersection of Two Linked Lists

I Problem

Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

For example, the following two linked lists begin to intersect at node c1:

The test cases are generated such that there are no cycles anywhere in the entire linked structure.


MikeAbout 3 minlinkedlisteasyhash tablelinked listtwo pointers
19, Remove Nth Node From End of List

I Problem

Given the head of a linked list, remove the nᵗʰ node from the end of the list and return its head.

Example 1

Input: head = [1, 2, 3, 4, 5], n = 2
Output: [1, 2, 3, 5]

Example 2
Input: head = [1], n = 1
Output: []


MikeAbout 3 minlinkedlistmediumlinked listtwo pointers
24, Swap Nodes in Pairs

I Problem

Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)

Example 1

Input: head = [1, 2, 3, 4]
Output: [2, 1, 4, 3]


MikeAbout 1 minlinkedlistmediumlinked listrecursion
206, Reverse Linked List

I Problem

Given the head of a singly linked list, reverse the list, and return the reversed list.

Example 1

Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]

Example 2

Input: head = [1, 2]
Output: [2, 1]

Example 3
Input: head = []
Output: []


MikeAbout 1 minlinkedlisteasylinked listrecursion
707, Design Linked List

I Problem

Design your implementation of the linked list. You can choose to use a singly or doubly linked list.

A node in a singly linked list should have two attributes: val and next. val is the value of the current node, and next is a pointer reference to the next node. If you want to use the doubly linked list, you will need one more attribute prev to indicate the previous node in the linked list. Assume all nodes in the linked list are 0-indexed.


MikeAbout 6 minlinkedlistmediumlinked listdesign
2