1729. Binary Search Tree Iterator II

Medium
Stack
Tree
Design
Binary Search Tree
Binary Tree
Iterator

Description

Hints

Hint 1
The inorder traversal of a BST gives us the elements in a sorted order.
Hint 2
We can use a stack to simulate the inorder traversal of the BST.
Hint 3
We can use another stack as a buffer to store numbers returned from calls to next and use this buffer whenever prev is called.

Statistics

Acceptance
63.3%
Submissions
26,888
Accepted
17,026