Last active
August 28, 2017 12:49
-
-
Save kutyel/b4b4e642d4eea70730837d448b5ba52a to your computer and use it in GitHub Desktop.
My Interview with Amazon Scotland π―
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 characters
| /* | |
| * Task 1 | |
| * Visible nodes in a node subtree | |
| */ | |
| const solution = T => visibles(T, -100000) | |
| const visibles = (T, max) => { | |
| if (T === null) return 0 | |
| let num = 0 | |
| if (T.x >= max) { | |
| num = 1 | |
| max = T.x | |
| } | |
| return num + visibles(T.l, max) + visibles(T.r, max) | |
| } |
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 characters
| /* | |
| * Task 2 | |
| * Array of pointers until -1 | |
| */ | |
| const solution = A => { | |
| let index = 0, values = 0 | |
| while (index !== -1) { | |
| index = A[index] | |
| values++ | |
| } | |
| return values | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment