Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The inorder traversal of a BST gives us the elements in a sorted order.
We can use a stack to simulate the inorder traversal of the BST.
We can use another stack as a buffer to store numbers returned from calls to next and use this buffer whenever prev is called.