What does it mean by the next smallest?


  • 13
    B

    Can some one give one example?


  • 2
    B

    It means the inOrder successor for the current element. Inorder successor of a node 'n' is the next node you would visit after node 'n' when you perform inOrder traversal of the BST.


  • 0
    B

    I got understand about this problem. It just means that you return the element one by one in BST when they are sorted in ascent order. So you just return the next smallest element one by one. So the description of the problem is OK.
    Thanks.


  • 2
    M

    And what do you get the first time you call next() ? The smallest element in the tree, or the root?


  • 10
    A

    The instruction "Your iterator will be initialized with the root node of a BST." is misleading. From running the test cases only did I realize the problem is just asking you to implement an iterator for in-order traversal of BST. Perhaps it's better to change the wording to that, or give some examples. Otherwise the coder wouldn't realize this until after they've implemented the wrong code and run the test case.


  • 0
    S

    @atruecubsfan thumbs up


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.