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.
Can I achieve begin insertion on a binary tree in O(log(N))?
Algorithm to synthesize a set of 2D points
implementation details of EvoSuite
Algorithm of searching minimal distance between sequences of points
Algorithm for recursively linked objects
Continuing a pattern of integer arrays
Generating Audio Fingerprint From an Audio with Echonest
Sum of Product of All Possible Combinations in an Array
How to find Strongly Connected Components in a Graph?
Find number of paths in grid with certain restrictions
Print/Output variable values to immediate window
S items, M Buckets Weighted Selection Algorithm
How to prove the optimality of this greedy algo?
Master method does not solve all questions [closed]
Cut an AABB by an OBB
Shortest path with even number of edges