Search⌘ K

DIY: Binary Search Tree Iterator

Explore how to implement a binary search tree iterator class in Java. Understand the design of next and hasNext methods to traverse a BST in ascending order. This lesson helps you develop iterative solutions for tree-based data structures, essential for coding interviews.

Problem statement

In this challenge, you have to implement a binary search tree iterator class called BSTIterator. The iterator will be initialized by the root node of the BST. You have to implement two methods:

  • next(): This will return the next smallest number in the BST.
...