Minimum Absolute Difference in BST via Inorder Traversal

Day 58/100 of #100DaysOfCode 🚀 Minimum Absolute Difference in a BST (Leetcode) For a Binary Search Tree, an in-order traversal produces values in sorted order.So, the minimum absolute difference will always be between two consecutive nodes in this order. Approach: Used DFS (in-order traversal): left → root → right Maintained: prev → previously visited node value minDifference → smallest difference found so far At each node: Calculated root.val - prev (only if prev exists) Updated minDifference with the minimum value Updated prev after visiting the current node. #Day58 #100DaysOfCode #LeetCode #BST #BinaryTree #InorderTraversal #DFS #Java #DSA #ProblemSolving #Consistency

  • text

To view or add a comment, sign in

Explore content categories