Good day Karthik,

Sorry I took so long to reply.

I am not sure I follow what you are saying.

Could you please rephrase the comment or send me a link to an article / reference that discusses the subject you brought up?

I will reply shortly after receiving your update.

Sincerely;

John

]]>Hi Rebecca,

Thanks for the message.

Tried looking for the typo on the post at no avail.

Will keep in mind your suggestion.

Regards;

John

Olav,

Thanks for the comment.

I have updated the post to include additional information.

I have clarified what I understand for the requirements of the problem.

Of course I MIGHT BE WRONG.

I believe you can not ask the interviewer for clarification.

Based on my assumptions the tree values represent the same information.

If you can let me know I missed in the requirements, I will make the necessary code changes.

Regards;

John

]]>John,

If you have a root – right – left

Your solution seems to return a 3 for the solution.

When the correct answer is 1.

For the facebook problem you are trying to solve the root node is not included because counting left most nodes on a root node with no subnodes returns zero.

Would you agree?

Thanks for your time.

Olav

]]>John,

Thanks for taking the time to reply. Sorry to keep bothering you but I just wanted to clarify one thing and just to be sure this is just for the facebook problem to solve and nothing else.

I was strictly looking at the Facebook problem: Number of visible “leftmost”nodes.

For their example of 8 at the root left 3 etc. that you pointed out:

Your result is 4 including the root node.

The facebook output is 4 not including the root node.

For example the output leftmost nodes would be : [3,1,4,13]

using their example.

Would you agree with this?

Thanks again.

]]>Hi Olav,

Thanks for the message.

The value returned by the function counts the root node.

I believe if you look at the tree from the left you will always see the root node.

The solution should not contain a null node.

The solution asks how many nodes would we see.

The code displays the tree doing a BFS to get a better idea.

The display IS NOT PART OF THE SOLUTION.

Another way to think of this problem which could be easier and might provide additional insights

would be to compute the depth of the tree. No matter if you look from the left or the right,

the number of visible nodes will be the SAME.

What could change is the values of the nodes, but the number would be the same.

You might want to take a look at the post “Maximum Depth of a Binary Tree” in my blog.

Hope my comments make sense.

Regards;

John

John,

Thanks for the reply.

I don’t believe the root node is counted in the output though.

The solution should be 2 visible nodes I believe.

Regards,

Olav

P.S. Don’t you think the solution should not contain “null” ?

]]>Hello Olav,

Thanks for the message.

I believe the following diagram illustrates the example at hand.

10

\

15

\

5

We have a root node (10), a child on the second level (15) and a child on the third level (5).

Test case:

10,null,15,null,5

main <<< arr: [10, null, 15, null, 5]
main <<< bfs:
10
null 15
null 5
main <<< visibleNodes: 3
If you look at the tree from the left you should see:
10
15
5
which represent 3 visible nodes.
Regards;
John