Linked List
Linked List
Day 2
01
Day 3
Day 4
02
Day 5
03
Important Practice Questions
01. Delete Node in a Linked List
There is a singly-linked list head and we want to delete a
node node in it.
You are given the node to be deleted node. You will not
be given access to the first node of head.
Practice
06
02. Middle of the Linked List
Given the head of a singly linked list, return the middle
node of the linked list.
Example 1:
Example 2:
Practice
07
03. Reverse Linked List
Given the head of a singly linked list, reverse the list, and
return the reversed list.
Example 1:
Practice
08
04. Linked List Cycle
Given head, the head of a linked list, determine if the
linked list has a cycle in it.
Example 1:
Practice
09
05. Linked List Cycle II
Given the head of a linked list, return the node where the
cycle begins. If there is no cycle, return null.
Example 1:
Practice
10
06. Palindrome Linked List
Given the head of a singly linked list, return true if it is a
palindrome or false otherwise.
Example 1:
Example 1:
Practice
11
07. Odd Even Linked List
Given the head of a singly linked list, group all the nodes
with odd indices together followed by the nodes with
even indices, and return the reordered list.
Note that the relative order inside both the even and odd
groups should remain as it was in the input.
You must solve the problem in O(1) extra space
complexity and O(n) time complexity.
Example 1:
Practice
12
08. Remove Nth Node From End of List
Given the head of a linked list, remove the nth node from
the end of the list and return its head.
Example 1:
Example 2:
Input: head = [1], n = 1
Output: []
Practice
13
09. Delete the Middle Node of a Linked
List
You are given the head of a linked list. Delete the middle
node, and return the head of the modified linked list.
Example 1:
Practice
14
10. Sort List
Given the head of a linked list, return the list after sorting
it in ascending order.
Example 1:
Practice
15
11. Intersection of Two Linked Lists
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.
Example 1:
Practice
16
12. Add Two Numbers
You are given two non-empty linked lists representing
two non-negative integers. The digits are stored in
reverse order, and each of their nodes contains a single
digit. Add the two numbers and return the sum as a linked
list.
Example 1:
Practice
17
13. Reverse Nodes in k-Group
Given the head of a linked list, reverse the nodes of the
list k at a time, and return the modified list.
You may not alter the values in the list's nodes, only
nodes themselves may be changed.
Example 1:
Practice
18
14. Rotate List
Given the head of a linked list, rotate the list to the right
by k places.
Example 1:
Example 1:
Practice
19
15. Copy List with Random Pointer
A linked list of length n is given such that each node
contains an additional random pointer, which could point
to any node in the list, or null.
Practice
20
16. Linked List Components
You are given the head of a linked list containing unique
integer values and an integer array nums that is a subset
of the linked list values.
Example 1:
Practice
21
17. Split Linked List in Parts
Given the head of a singly linked list and an integer k, split
the linked list into k consecutive linked list parts.
Example 1:
Practice
22
18. Remove Zero Sum Consecutive
Nodes from Linked List
Given the head of a linked list, we repeatedly delete
consecutive sequences of nodes that sum to 0 until there
are no such sequences.
After doing so, return the head of the final linked list. You
may return any such answer.
Example 1:
Input: head = [1,2,-3,3,1]
Output: [3,1]
Example 2:
Input: head = [1,2,3,-3,4]
Output: [1,2,4]
Practice
23
19. Swapping Nodes in a Linked List
You are given the head of a linked list, and an integer k.
Example 1:
Practice
24
20. Design Browser History
You have a browser of one tab where you start on the
homepage and you can visit another url, get back in the
history number of steps or move forward in the history
number of steps.
Example:
Input:
["BrowserHistory","visit","visit","visit","back","back","forw
ard","visit","forward","back","back"]
[["leetcode.com"],["google.com"],["facebook.com"],
["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]
Output:
[null,null,null,null,"facebook.com","google.com","faceboo
k.com",null,"linkedin.com","google.com","leetcode.com"]
Practice
25