Got this question in the first round of Onsite interview and wasn't able to code the solution almost all the time went into discussion around it. If anyone can help that would be helpful.
A mountain can be simplified as an isoceles right triangle, whose base rests on the x-axis. The two sides of the mountain are both at 45 degress to the base so the peak of the mountain forms a right angle.
All the mountains are the same color so a mountian is invisible if its peak lies on or within the triangular shape of any other mountain.
Given a list of positions of all the mountain's peaks (x-y coordinates). Output the number of visible mountains.
- (4, 6)
- (7, 2)
- (2, 5)
Point to note:
- here the peak visible are 1 and 3
- Mountains are of the same colour so you have to find the peaks which are visible. The question eventually was about the area covered by a triangle; if any peak point comes into that triangle, then that peak is not visible.