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.
#!/bin/python3importsysn,k=input().strip().split(' ')n,k=[int(n),int(k)]x=[int(x_temp)forx_tempininput().strip().split(' ')]x=sorted(x)#logic# 2 4 5 6 7 9 12# Go as right as possible for first iteration# Again go as right as possible for second iteration# what does this mean that place transmitter in a such way that it will handle houses on left and right sides comfortably# So first you are at left most position.. iterate over and find middle position where (middle-left==k) and then find right most position where (right-middle<=k)count_trans=0last=x[0]i=0while(i<n):count_trans=count_trans+1next_point=x[i]+kwhile(i<nandx[i]<=next_point):i=i+1next_point=x[i-1]+kwhile(i<nandx[i]<=next_point):i=i+1print(count_trans)
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 →