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

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

Categories

HOME
search
apache-jena
webdriver
css3
rsa
knitr
bitbucket-api
edge
dojo
3d-reconstruction
pearson-correlation
google-cloud-datalab
qpython
drop-down-menu
endpoint
nancy
searchview
dreamweaver
fileserver
nim
database-connection
simpleitk
symbols
custom-post-type
motion-detection
underscore.js
soot
constexpr
cognos-bi
github3.py
login-script
gnat-gps
searchkit
wurfl
release
sim-card
linq-to-objects
jvmti
wmp
preloader
strftime
snapchat
reportservice2010
singleinstance
colorbar
edit
filehandle
cup
reshape
cmp
vibrate
winusb
xcode-server
android-dateutils
simevents
http-status-code-401
angular-ui-typeahead
state-restoration
rewrite
rubaxa-sortable
sapscript
sony-lifelog-api
airbrake
aspectj-maven-plugin
node-serialport
entity-framework-4.3
jama
xml-namespaces
extjs2
model-driven-development
ebay-lms
mvc-editor-templates
pagedown
rmiregistry
extconf.rb
objectquery
cgimage
user-tracking
saxparseexception
android-holo-everywhere
google-ajax-api
multiplatform
aspmenu
application-verifier
sifr
spread
feasibility
localizable.strings
change-management

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