Tree and Graph Challenges Comments
Comments

Here's some code to set up the tree in Java so you can just do the algorithm.

I have a doubt ! In this Output
Input:
4
2 6 9 11
7 8 9 8
6 7 12 9
10 7 6 4Output(given as) :
B A A A
B B B A
C B B B
C C B BCan anyone explain the output of this case please?

If 11 is the peak element then how come 6,9 and 8 which is marked as A in output is treated
a areas of peak element. Can anyone could please give me a example ? 
9 and 8 can each be reached by going down from 11 so they're part of Area A. Similarly the 6 on top can be reached by going down from the 9, so it also ends up as part of A.

Why does the top 6 ends up beaing part of A and not B?
@Learneroo Could you please explain in detail how the areas are determined in the last example? I can't figure out how the top 2, 7, and 8 are reached by the 12 peak.
Cells that can be reached by continuously descending (in 4 directions) from a peak are controlled by that peak.
A cell that can be reached by descending from more than one cell belongs to the area of the the highervalue cell
That would leave us with:
Peaks:
10, 11, 12
Step 1?
C 6 9 A C 8 9 8 C 7 B 9 C C C C
Step 2?
A A A A C 8 9 A C 7 B A C C C A
How?
B A A A B B B A C B B B C C B B
Thank you for your help!

When a cell is surrounded by multiple cells of higher values, it joins the area of the higher valued cell (regardless of who's peak is higher). It might be easier to work from the small cells back to the peaks, instead of from the peaks down.
So the 2 could be controlled by the 6 or 7, but it joins the 7 since 7>6. The path then continues from 7 > 8 > 9 > 12.

pay attention to the fact that the explorer can only move right or down!
Panashe Fundira
Jun 17, 11:23 AMit was a good challenge figuring out how to do this with the array representation, very satisfied to have solved it