You are viewing a single comment's thread. Return to all comments →
Java. Not the best solution, I think, but it works.
public static int hackerlandRadioTransmitters(List<Integer> x, int k) { x.sort(Integer::compareTo); int count = 1; int currentBranchStart = x.get(0); boolean isLeftBranch = true; for (int i = 1; i < x.size(); i++) { int currentLocation = x.get(i); int prevLocation = x.get(i - 1); if (currentLocation - prevLocation > k) { count++; currentBranchStart = currentLocation; isLeftBranch = true; continue; } if (currentLocation - currentBranchStart > k) { if (isLeftBranch) { currentBranchStart = prevLocation; } else { currentBranchStart = currentLocation; count++; } isLeftBranch = !isLeftBranch; } } return count; }
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. Not the best solution, I think, but it works.