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.
How to compute Probability of winning atleast k out of N games
How to calculate time complexity when two iteration involved with different inputs?
How to implement a counter that decays over time?
Understanding running time for merge sort and quick sort
Big O Notation for a For-Loop
Implementation of Graph Coloring Algorithms [closed]
Displaying the most relevant advertisements to web users based on their visited pages
What are good data structures to group these features? and what algorithms can be used for inserting and retrieving?
Will a standard Kruskal-like approach for MST work if some edges are fixed?
Algorithm - Find a series of Sophie Germain prime numbers
Balanced Partition greedy approach
Chunking algorithm for any type of data
General purpose algorithms that make use of presorting and their efficiency
confusion about Kadane’s Algorithm?
for a given path between node u-v in tree find maximum XOR with any node in that path
MST with special conditions