[Hacker Rank] Hackerland Radio Transmitters

Hackerland Radio Transmitters

  • Time : O(nlogn)
  • Space : O(1)
1
2
3
4
5
6
7
8
9
10
11
12
int hackerlandRadioTransmitters(vector<int> x, int k) {
sort(begin(x), end(x));
int res = 0, cover = INT_MIN;
for(auto& h : x) {
if(cover >= h) continue;
res++;
auto ub = upper_bound(begin(x), end(x), h + k);
--ub;
cover = *ub + k;
}
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/06/11/PS/HackerRank/hackerland-radio-transmitters/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.