Created
September 8, 2016 20:47
-
-
Save gfodor/72c1004dc7fe5eb0a5db8e47c1d7f50f to your computer and use it in GitHub Desktop.
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
function newNode(data, parent) { | |
return { data: data, parent: parent }; | |
} | |
function deepestCommonAncestorOf(x, y) { | |
// Your code here | |
} | |
function assertEquals(x, y) { | |
if (x !== y) { | |
console.error("FAIL " + x + " != " + y); | |
} else { | |
console.log("OK " + x + " == " + y); | |
} | |
} | |
// 1 | |
// 2 3 | |
// 4 5 | |
// 6 | |
var node_1 = newNode(1, null); | |
var node_2 = newNode(2, node_1); | |
var node_3 = newNode(3, node_1); | |
var node_4 = newNode(4, node_3); | |
var node_5 = newNode(5, node_3); | |
var node_6 = newNode(6, node_5); | |
assertEquals(3, deepestCommonAncestorOf(node_6,node_4).data); | |
// Your tests here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment