# Locked Binary Tree

Contributed by
Rakesh Tiwari
Easy
0/40
8 mins
100 %

## Problem Statement

#### A node will be locked only when some or all of the ancestors or the node itself is locked.

##### EXAMPLE:
``````Input:
'N' = 5, βKβ = 3
βARRβ = [-1, 0, 0, 1, 2]
βLOCKβ = [0, 0, 1, 0, 0]

Output: β1β
``````

``````In the above tree in the simple path from node β4β to root β1,β the nodes encountered are [0, 1, 3], and no node from the set is locked. Hence node β3β can be locked.
``````
Detailed explanation ( Input/output format, Notes, Images )
##### Constraints :
``````1 <= 'T' <= 10
1 <= 'N' <= 10^5
0 <= βKβ <= βN-1β
0 <= βPAR[i]β <= βN-1β
0 <= βLOCK[i]β <= 1

Time Limit: 1 sec
``````
##### Sample Input 1 :
``````2
5 0
-1 0 3 0 3
1 1 1 0 0
4 1
3 2 -1 1
1 0 0 1
``````
##### Sample Output 1 :
``````0
1
``````
##### Explanation Of Sample Input 1 :
``````In the first test case,
``````

``````In the above tree the target node β0β is itself locked, so it cannot be locked.

In the second test case,
``````

``````In the above tree in the simple path from node β1β to root β2β the nodes encountered are [1, 2], and no node from the set is locked.
``````
##### Sample Input 2 :
``````2
4 2
-1 0 1 1
0 1 0 0
4 3
-1 0 1 2
1 0 0 0
``````
##### Sample Output 2 :
``````0
0
``````
Autocomplete
Console