138. 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. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state....

<span title='2022-01-31 00:00:00 +0000 UTC'>January 31, 2022</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

426. Convert Binary Search Tree to Sorted Doubly Linked List

Convert a Binary Search Tree to a sorted Circular Doubly-Linked List in place. You can think of the left and right pointers as synonymous to the predecessor and successor pointers in a doubly-linked list. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element. We want to do the transformation in place. After the transformation, the left pointer of the tree node should point to its predecessor, and the right pointer should point to its successor....

<span title='2022-01-27 00:00:00 +0000 UTC'>January 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

23. Merge k Sorted Lists

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. 1 2 3 4 5 6 7 8 9 10 11 12 Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6 1 2 3 4 Example 2: Input: lists = [] Output: [] 1 2 3 4 Example 3: Input: lists = [[]] Output: [] Constraints:...

<span title='2021-10-19 00:00:00 +0000 UTC'>October 19, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

951. Flip Equivalent Binary Trees

For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations. Given the roots of two binary trees root1 and root2, return true if the two trees are flip equivelent or false otherwise....

<span title='2021-10-19 00:00:00 +0000 UTC'>October 19, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

21. Merge Two Sorted Lists

21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: l1 = [], l2 = [] Output: [] Example 3: Input: l1 = [], l2 = [0] Output: [0] Constraints:...

<span title='2021-07-16 00:00:00 +0000 UTC'>July 16, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

83. Remove Duplicates from Sorted List

1625. Lexicographically Smallest String After Applying Operations Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. 1 2 3 4 Example 1: Input: head = [1,1,2] Output: [1,2] 1 2 3 4 Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] Constraints: The number of nodes in the list is in the range [0, 300]. -100 <= Node....

<span title='2021-06-22 00:00:00 +0000 UTC'>June 22, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

206. Reverse Linked List

206. Reverse Linked List Given the head of a singly linked list, reverse the list, and return the reversed list. 1 2 3 4 Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] 1 2 3 4 Example 2: Input: head = [1,2] Output: [2,1] 1 2 3 4 Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is the range [0, 5000]. -5000 <= Node....

<span title='2021-06-17 00:00:00 +0000 UTC'>June 17, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

24. Swap Nodes in Pairs

24. Swap Nodes in Pairs 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.) 1 2 3 4 Example 1: Input: head = [1,2,3,4] Output: [2,1,4,3] 1 2 3 4 5 6 7 8 9 Example 2: Input: head = [] Output: [] Example 3: Input: head = [1] Output: [1] Constraints:...

<span title='2021-06-17 00:00:00 +0000 UTC'>June 17, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

237. Delete Node in a Linked List

237. Delete Node in a Linked List Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list. 1 2 3 4 5 Example 1: Input: head = [4,5,1,9], node = 5 Output: [4,1,9] Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function....

<span title='2021-06-16 00:00:00 +0000 UTC'>June 16, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

19. Remove Nth Node From End of List

19. 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. 1 2 3 4 Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] 1 2 3 4 5 6 7 8 9 Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints:...

<span title='2021-06-14 00:00:00 +0000 UTC'>June 14, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

2. Add Two Numbers

2. 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. You may assume the two numbers do not contain any leading zero, except the number 0 itself. 1 2 3 4 5 Example 1: Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807....

<span title='2021-06-14 00:00:00 +0000 UTC'>June 14, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

328. Odd Even Linked List

328. 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. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. 1 2 3 4 Example 1: Input: head = [1,2,3,4,5] Output: [1,3,5,2,4] 1 2 3 4 Example 2: Input: head = [2,1,3,5,6,4,7] Output: [2,3,6,7,1,5,4] Constraints:...

<span title='2021-05-20 00:00:00 +0000 UTC'>May 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx