Hackerland Radio Transmitters

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
      x.sort()
      antenas = []
      i = 0
    
      while i<len(x):
        house = x[i]
        antena = house
        y = i + 1
        # print('---------------------')
        # print(f'house={house}, y={y}, antenas = {antenas}, antena:{antena}')
    
        if y >= len(x):
          antenas.append(antena)
          break
        while x[y] <= (house + k) and y<len(x):
          antena = x[y]
          y += 1
          if y >= len(x): break
    
        antenas.append(antena)
        i = y
        if i >= len(x): break
    
        while x[i] <= antena + k and i<len(x):
          i += 1
          if i >= len(x): break
    
      # return (antenas)
      return len(antenas)