You need to sign in or sign up before continuing.×
Ad
  • Custom User Avatar

    The description clearly states the second example is a valid BST which it isn't or am I incorrect in that statement?

    Furthermore,
    ' you will write a function that will validate that a given binary tree is a binary search tree. '
    please provide a reference to a binary search tree definition that states a reverse order is a valid binary search tree.

  • Custom User Avatar

    Second Example is NOT A VALID BST! and the corresponding test is incorrect

    by definition, valid BST's have the following properties :

    • The left subtree of a node contains only nodes with values lesser than the node’s value.
    • The right subtree of a node contains only nodes with values greater than the node’s value.
    • The left and right subtree each must also be a binary search tree.
  • Custom User Avatar

    Posting in case anybody else runs into the same issues or can point out where I did something wrong...

    My logic was verified by logs that a reversed linked list was being created and returned.
    what i tried (in JS):

    • completed by rewiring extg nodes in place
    • completed by creating newNodes with data obtained in traversal
    • returned reference to reversed list
    • returned list with a reassignment to the reversed list

    A couple notes here to piggyback on the others' comments:
    1st assertion of the "should be able to handle lists of length 3" is just wrong - assertion checks for equality with an unreversed list (1 -> 3 -> 8 against 1 -> 3 -> 8)

    The rest of the assertions for lists of lengths > 1 don't seem to work unless we edit tests to reassign list as the evaluation of the test's call to reverse(). Then the assertion tests the evaluated result of our logic and my tests passed as expected.

    This makes sense if returning a new reference in memory but should not matter if we're returning list... right? This hangup is probably due to yellowBirdy's comment below but in any case the instructs aren't explicit on whether to reverse in place or to not mutate the input list.

    Hope this helps some of y'all!