Converting Sorted List to Balanced BST with Two Pointers and Recursion

Day 87 of #100DaysOfCode Today I solved "Convert Sorted List to Binary Search Tree" on LeetCode using Two Pointers + Recursion. Key Idea: A sorted linked list can be converted into a height-balanced BST by always choosing the middle element as root. Approach: • Use slow & fast pointers to find the middle node • Middle node becomes the root • Left part → build left subtree • Right part → build right subtree Repeat this process recursively to construct the entire BST. Concepts Used: • Linked List • Binary Search Tree (BST) • Two Pointers (Slow & Fast) • Recursion Time Complexity: O(n log n) Space Complexity: O(log n) This problem helped me understand how to transform one data structure into another efficiently From lists → to trees… leveling up data structure mastery #Day87 #100DaysOfCode #LeetCode #BST #LinkedList #Recursion #Cpp #CodingJourney

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories