How to take input for this question in java?

I know how to solve this and I solved it on leetcode but don’t know how to take the input in java on coding blocks website. Please help me with this.

hello @hemu1999
u r given a level order traversal.
so first u need to construct the tree using level order traversal.
and then u need to apply ur logic.

for creating tree ->
to construct a tree from level order , we perform level order traversal only .
look at this code.

this code is exaclty similar to level order traversal.
we pop node from q.
now we check whether its left node exist or not by checking value of c1 . it exist we create a new node and add it to the left of current node. and push that newly created node in q.

similarly we do for right node.
and at end when q get empty .
the tree construction is done and we return root of the tree.

change syntax as per ur language ,logic remains the same

see this code and help me what is wrong?

its working.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.