You are viewing a single comment's thread. Return to all comments →
Java O(n log n)
public static int hackerlandRadioTransmitters(List<Integer> x, int k) { Collections.sort(x); int transmitters = 0; int i = 0; while (i < x.size()) { int location = x.get(i); transmitters++; int nextCoverage = location + k; while (i < x.size() && x.get(i) <= nextCoverage) { i++; } int lastHouseInRange = x.get(i - 1); while (i < x.size() && x.get(i) <= lastHouseInRange + k) { i++; } } return transmitters; }
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 →
Java O(n log n)