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.

Related Links

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

Categories

HOME
notepad++
kentico
porting
fpga
rdbms
google-spreadsheet
rsa
owl-carousel
visual-studio-emulator
settings
python-multithreading
banner
g++
jquery-ui-sortable
plist
xcodebuild
onedrive-api
bitnami
modbus-tcp
aws-sdk
smartclient
soci
production
nodemcu
user-experience
event-store
froala
beautifier
interbase
jackson-modules
jasmine-node
subclass
iis-express
postback
sql-server-2000
autolisp
card.io
twos-complement
getpixel
pop3
zoomify
jpad
google-earth-engine
node-mssql
jvmti
linqpad
http-request
angular-http
memory-mapping
openal
dotnet-httpclient
mongotemplate
reindex
otp
trigger.io
rxtx
android-instrumentation
reachability
taocp
flex-monkey
redistributable
centrifuge
lrs
i386
cifilter
pre-build-event
omniauth-facebook
cda
dbamp
html-to-pdf
fuzzywuzzy
blitline
user-management
ascii-art
qt5.2
avisynth
ocra
keyup
kubuntu
zxspectrum
shopizer
adehabitathr
document-repository
dct
dsym
scriptaculous
mbunit
jeromq
cffile
abstract-data-type
composite-component
wp7test
resource-management
rmiregistry
ilasm
agility.js
mysql-error-1205
listactivity
dot-emacs
request-headers
qtabbar
feasibility
cldc
wysiwym
fault-tolerance
change-management
blind

Resources

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