Popular question asked in Google, Amazon or other big companies.
Given a binary tree with 3 pointers as (left, right & sibling), sibling is currently blank/Null. Give an algorithm to fill the sibling field for each node, such that it will be pointing to the next node at the same level.
Below are 3 ways to do the same job but with different runtime & space complexities, so choose the one which fits to your work -
Below are 3 ways to do the same job but with different runtime & space complexities, so choose the one which fits to your work -
These are 3 ways I got to know through various resources for the question asked. But I think, first it takes some time to think about the approach, then it takes further time to implement for that approach. And for me it becomes almost impossible to think freely when someone sitting on my head to get the solution. And in these interviews, people expect you to code also, that too perfectly. For me it took 1 day to implement for the apprach I thought & for implementation I had to refer the internet.