Skip to content

Completed LinkedLists-2#1429

Open
sarvanibaru wants to merge 1 commit intosuper30admin:masterfrom
sarvanibaru:master
Open

Completed LinkedLists-2#1429
sarvanibaru wants to merge 1 commit intosuper30admin:masterfrom
sarvanibaru:master

Conversation

@sarvanibaru
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Your solution for the BSTIterator problem is excellent. It correctly implements the in-order traversal using a stack with lazy evaluation, which meets the problem requirements. The time and space complexities are correctly analyzed, though note that the space complexity is more precisely O(h) (the height of the tree) rather than O(n) in the worst case. However, in the worst case (a skewed tree), h = n, so O(n) is not wrong. But for the purpose of this problem, O(h) is the expected answer as per the follow-up.

The code is clean and easy to understand. The helper method is well-named and efficiently handles pushing the left nodes. One minor point: the helper method is called helper, but it might be more descriptive to name it dfs or pushLeft to indicate its purpose more clearly. However, this is a matter of preference.

Overall, great job! You have successfully implemented the BST iterator with the required time and space complexities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants