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.
- Hackerland Radio Transmitters
- Discussions
Hackerland Radio Transmitters
Hackerland Radio Transmitters
Sort by
recency
|
19 Discussions
|
Please Login in order to post a comment
Python:
Python, typical greedy algorithm
Java O(n log n)
Python 3 with greedy algorithm: O(n) time and space complexity.
x.sort() count=0 while x: leftHouse=x[0]#this provides the latest left house that does not have connection #print('leftHouse',leftHouse) while x and leftHouse+k >=x[0]:#this part ensures that the value added covers all left houses using loop ,when the value goes out of transmitters reach loop breaks # print('leftHouse+k',leftHouse+k,'>=x[0]',x[0],'x=',x) transmitter =x.pop(0)#this iteration places transmitter # print('new value of x after pop',x) ## print('transmitter',transmitter) while x and transmitter+k>=x[0]:#this side handles right side of the transmission print('transmitter loop pop',x.pop(0))#this is more or less doing an increment #print('new value of s after pop',x) count+=1 return count