Move the pointer to required tree level.
static TreeNode movePointer(TreeNode root, int level) { if (level == 0) return root; return movePointer(root.children[root.children.length - 1], level - 1); }