Created
October 1, 2019 22:56
-
-
Save vbrazo/61fb8e78cfd4040eb0677e3af76f284b to your computer and use it in GitHub Desktop.
Revisions
-
vbrazo created this gist
Oct 1, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ # =begin # # Given a Balanced Binary Tree (BBT) # # (non-sorted, non-search, containing unique elements) # 42 # / \ # / \ # / \ # / \ # 81 99 # / \ / \ # 17 1 25 19 # / \ / \ / \ / \ # 8 -1 2 9 5 6 3 31 # and its array representation: # [42, 81, 99, 17, 1, 25, 19, 8, -1, 2, 9, 5, 6, 3, 31] # Write a function that will take any BBT array of integers # (structured in the manner above), and an integer in that array, # and return a list of "zigzag" directions to get to that destination, # starting from the root. # To go left, adds "zig" # To go right, adds "zag" # Example: # tree = [42, 81, 99, 17, 1, 25, 19, 8, -1, 2, 9, 5, 6, 3, 31] # zigzag_directions(tree, 42) -> [] # zigzag_directions(tree, 31) -> ['zag', 'zag', 'zag'] # zigzag_directions(tree, -1) -> ['zig', 'zig', 'zag'] # zigzag_directions(tree, 100) -> None # zigzag_directions(tree, 1) -> ['zig', 'zag'] # zigzag_directions(tree, 6) -> ['zag', 'zig', 'zag'] # =end