Hackerland Radio Transmitters

  • + 0 comments

    JavaScript Solution:- function hackerlandRadioTransmitters(x, k) { // Sort the house locations x.sort((a, b) => a - b);

    let i = 0;
    let count = 0;
    let n = x.length;
    
    while (i < n) {
        count++;
        let loc = x[i] + k; // Find the farthest house that can be covered by a transmitter
        while (i < n && x[i] <= loc) i++; // Move to the farthest house within range
    
        i--; // Place the transmitter at the farthest house within range
        loc = x[i] + k; // Define the coverage of this transmitter
    
        while (i < n && x[i] <= loc) i++; // Skip all covered houses
    }
    
    return count;
    

    }