dsa1 min read
Convert Sorted List to BST — Fast/Slow + Recursion
Convert a sorted linked list to a height-balanced BST by repeatedly finding the middle node as root.
Read →
1575 articles
Convert a sorted linked list to a height-balanced BST by repeatedly finding the middle node as root.
Reverse every k nodes of a linked list recursively: check k nodes exist, reverse them, recurse on the rest.
Merge k sorted linked lists into one sorted list using a min-heap for O(n log k) time complexity.
Sort a linked list in O(n log n) time and O(1) space using bottom-up merge sort with doubling sublist sizes.
Build a balanced BST from a sorted list in O(n) by counting nodes, building in-order, and consuming list nodes.