Junaid Arshad’s Post

Solved Kth Smallest Element in a BST today Used an iterative inorder traversal (DFS with stack) to efficiently find the answer without extra space for storing nodes. Key idea: 👉 Inorder traversal of a BST gives nodes in sorted order 👉 So the k-th visited node is the answer Instead of recursion, I used a stack to simulate traversal: Go left as much as possible Process node Move right Clean, efficient, and interview-friendly ✅ Time: O(H + k) Space: O(H) (stack) Consistent practice is making these patterns feel natural 🚀 #LeetCode #DataStructures #Algorithms #Python #CodingInterview

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories