DIY: Binary Search Tree Iterator

Solve the interview question "Binary Search Tree Iterator" in this lesson.

Problem statement

In this challenge, you have to implement a binary search tree iterator type 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.
  • HasNext(): This will return true if the next smallest number exists in the tree.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.