Hackerland Radio Transmitters

Sort by

recency

|

416 Discussions

|

  • + 1 comment

    Test case #2: 7 2 9 5 4 2 6 15 12

    Expected output: 4

    I think the result should be 3. When sorting: [2, 4, 5, 6, 9, 12, 15] Result is: [2, 4, 5, 6] -> 1 transmitter [9, 12] -> 1 transmitter [15] -> 1 transmitter Total 3 transmitters. Any help? Thank you!

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
        t=0 #number of transmitters
        ind=0 #our location in Hackerland
        while ind<max(x): #Loops through the cities in list x
            if ind+1 not in x:
                ind+=1 #This makes sure we don’t place transmitters in places where there are no houses
            else:
                while ind+k+1 not in x:
                    ind-=1 #This makes sure that the center is one of the houses
                t+=1 #Adds a transmitter
                ind+=(2*k+1) #skips all the locations where the transmitter is reached
        return t #returns the amount of of 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)
    
  • + 0 comments

    If Hackerland is a one-dimensional city, it is impossible to install radio transmitters on the roofs of houses. With one dimension there is no "on" anything. XD

  • + 0 comments
    def hackerlandRadioTransmitters(x, k):
        # Write your code here
        # x = list(set(x))
        x = sorted(x)
        count = 0
        coverMax = 0
        idealCenter = 0
        actualCenter = 0
        for i in range(len(x)):
            if x[i] <= idealCenter:
                actualCenter = x[i]
                coverMax = actualCenter + k
                continue
            elif x[i] <= coverMax:
                continue
            else:
                count += 1
                idealCenter = x[i] + k
                actualCenter = x[i]
                coverMax = idealCenter
        return count