Hackerland Radio Transmitters

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
        size = len(x)
        if size == 1:
            return 1
            
        x.sort()
        num = 0
        i = 0
        while i < size:
            # mark the furthest location within the coverage at current i
            loc = x[i] + k
       
            # move to the furthest house within the range and set transmitter
            while i < size and x[i] <= loc:
                i += 1
            i -= 1
            num += 1
            
            # make the furthest location within the coverage at current i
            loc = x[i] + k
            
            # move to the first house outside the coverage
            while i < size and x[i] <= loc:
                i += 1
            
        return num