We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hackerland Radio Transmitters
You are viewing a single comment's thread. Return to all comments →
JavaScript Solution:- function hackerlandRadioTransmitters(x, k) { // Sort the house locations x.sort((a, b) => a - b);
}