We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# two modes: # a) looking for farthest house to provide covarege for current uncovered house (radio search)# b) looking for first house out of coverage from current house with radiodefhackerlandRadioTransmitters(locs,coverage):locs.sort()iflen(locs)==1:return1radiosearch=Truecurindex=0numradios=0whileTrue:otherindex=curindex+1whileotherindex!=len(locs)andlocs[otherindex]-locs[curindex]<=coverage:otherindex+=1ifradiosearch:numradios+=1curindex=otherindex-1#radiosearchendsonehousetoofarelse:curindex=otherindexifotherindex==len(locs):returnnumradiosradiosearch=notradiosearch
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hackerland Radio Transmitters
You are viewing a single comment's thread. Return to all comments →
Python, typical greedy algorithm