Created
October 1, 2019 22:56
-
-
Save vbrazo/61fb8e78cfd4040eb0677e3af76f284b to your computer and use it in GitHub Desktop.
This file contains 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 characters
# =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 |
Author
vbrazo
commented
Oct 1, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment