Merge K Sorted Linked Lists
Merge K sorted linked lists.
Input: lists = [[2,2,3],[1,5]]
Output: [1,2,2,3,5]
Explanation: Extracts the smallest current node iteratively using a priority queue to build a single merged and sorted linked list.
Pacific and Atlantic Water Flow
Calculate water flow from a matrix to the Pacific and Atlantic oceans.
Input: heights = [[2,1],[1,2]]
Output: [[0,0],[0,1],[1,0],[1,1]]
Explanation: All cells can flow to both oceans because water can move to adjacent cells of equal or lower height or directly off the edges.
Validate if a given tree is a valid binary search tree.
Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key, and the right subtree contains only nodes with keys greater than the node's key…
Reverse Nodes in k-Group
Reverse nodes in k-group in a linked list.
Input: head = [1,2,3,4,5], k = 3
Output: [3,2,1,4,5]
Explanation: The first 3 elements are reversed, while the remaining 2 are left untouched since they don't form a complete group.
Rotate a linked list to the right by k places.
Given the head of a linked list, rotate the list to the right by k places.
Input: head = [0,1,2], k = 4
Output: [2,0,1]
Explanation: The list has a length of 3. Rotating by 4 is mathematically equivalent to rotating by 1 (4 mod 3 = 1).