Skip to content

Instantly share code, notes, and snippets.

@kutyel
Last active August 28, 2017 12:49
Show Gist options
  • Save kutyel/b4b4e642d4eea70730837d448b5ba52a to your computer and use it in GitHub Desktop.
Save kutyel/b4b4e642d4eea70730837d448b5ba52a to your computer and use it in GitHub Desktop.
My Interview with Amazon Scotland πŸ’―
/*
* 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)
}
/*
* 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