### algorithm

#### Check the building that sees the farthest

```I'm trying to write a program in assembly that takes an x and y coordinate ,x will act as the position of a building and y will act as its height.
Now i'm supposed to check the building that sees the farthest.
For example:
As you can see in the example the building at position 8 sees 4 meters ,and at position 7 that building sees 2 meters, and at position 9 that building sees 9 meters which is the farthest distance ,so all i have to do now is print that 9 sees 9 meters and its the farthest distance.
I can't seem to figure out an algorithm to do so.
```
```Go from last to first while tracking the so far maximum height building and its location, and the "currently best solution"
When you encounter a new building:
If it's not higher than current maximal - it will never see more than current maximal (because current maximal sees until it, and will see further away from it).
If it's higher than current maximal - the interval between the new building and the previous highest building is a candidate to be "best", if it is better than the so far best solution.
When you reach the start, yield the best solution seen.
Example (based on your example):
10: highest is 10, so far best is null
9: found new highest, so far best is 10 with distance 1.
8: no new highest, 10 is best.
7: no new highest
...
0: update "best", 9 is the new best with distance of 9.
Yield: 9 as seeing furthest.```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization