Pergunta de entrevista da empresa Ooyala

Given an object hierarchy (like in JavaScript), write a function that returns the depth of an object in this tree which is passed to the function.

Respostas da entrevista

Sigiloso

30 de mar. de 2014

Depth of an element in a tree is just this: public static int depthOfX(SeraTree t, int x){ return depthOfX( t, x, 0); } public static int depthOfX(SeraTree t, int x, int level){ if ( t == null ) return -1; if (t.value == x) return level; level++; return Math.max(depthOfX(t.left,x,level), depthOfX(t.right,x,level)); }

Sigiloso

30 de dez. de 2010

Perfect syntax was not required