Check if the target node can be locked

Given a binary tree, find out whether a node represented as target node, can be locked or not.

A node (target) can be locked only when its ancestors and the node (target) itself is not locked.

Input will be the Binary Tree upto "N" levels and out-put should be the boolean value representing "true" if the target node can be locked or "false" otherwise.

Node Structure: -

TreeNode{ int val; boolean isLocked; TreeNode left; TreeNode right; }

Comments (2)