Skip to content

Linked-List-2 Done#1423

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

Linked-List-2 Done#1423
ManishaRana1195 wants to merge 1 commit intosuper30admin:masterfrom
ManishaRana1195:master

Conversation

@ManishaRana1195
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Your BSTIterator implementation is very close to correct. However, note that in the next() method, you should use the existing dfs method to traverse the right subtree's left nodes. Currently, you are directly pushing the right child and then its left descendants, but the dfs method already does this. By calling dfs(nextValue.right) instead of manually pushing, you can avoid code duplication and make the code cleaner.

Also, please note that the problem only requires the BSTIterator implementation. The other two files (IntersectionOfLinkedList and ReorderList) are not relevant to this problem and should not be included when submitting a solution for the BST Iterator problem. Focus on the specific problem requirements.

Overall, your solution is efficient and follows the expected approach. Keep up the good work!

@super30admin
Copy link
Copy Markdown
Owner

Your BSTIterator implementation is very close to correct. However, note that in the next() method, you should call dfs on the right child of the popped node unconditionally if you are using the standard approach. Your current code does this correctly. But let me clarify: the dfs function pushes all left nodes of the given root. So when you pop a node, you need to process its right subtree by calling dfs on the right child. This is exactly what you did.

One minor point: in the dfs function, you have a while loop that pushes nodes until the leftmost node is reached. This is standard.

However, you included solutions for other problems in the same submission. For the purpose of this problem (BSTIterator), you should only submit the BSTIterator class. Make sure to separate solutions for different problems into different files or submissions.

Also, your code comments mention "Space Complexity: O(1)" for BSTIterator, but actually it is O(h) due to the stack. Please correct that comment.

Overall, your BSTIterator solution is correct and efficient. Well done!

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