Hackerland Radio Transmitters

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
        locations = sorted(x)
        station_location = first_house_outside_coverage = one_side_covered = two_side_coverage_counter = 0
    
        while station_location < len(locations):
            station_location_0 = station_location
    
            while first_house_outside_coverage < len(locations) and locations[first_house_outside_coverage] <= locations[station_location] + k:
                first_house_outside_coverage += 1
    
            if first_house_outside_coverage == station_location_0 + 1 or one_side_covered:
                station_location = first_house_outside_coverage
                two_side_coverage_counter += 1
                one_side_covered = 0
            else:
                station_location = first_house_outside_coverage - 1
                one_side_covered = 1
    
        return two_side_coverage_counter