Search⌘ K
AI Features

DIY: Binary Search Tree Iterator

Understand how to implement the BSTIterator class that efficiently traverses a binary search tree to return the next smallest element. Learn to use the next() and has_next() methods to interact with the tree, enabling you to solve similar coding interview problems.

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.
...