Storing level of each node

i’m trying to solve this problem using first approach by storing the level of node using pair.where in the code should i increase level check it once.

hello @asifkarim073

can u pls explain me ur logic (only logic)

i am using bfs method , using a queue to store pairs.each pair of node consist of its address as well as level.
but there is some error like for the same level i am getting two different value.

so to remove this ,use hash map. (key -> level , value -> node data)
do level order trversal .
find level of each node and then
map[level]=data of the node.

once trversal is done .print the content of ur map

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.