Hackerland Radio Transmitters

  • + 0 comments

    C++20

    int hackerlandRadioTransmitters(vector<int> x, int k) {
        sort(x.begin(), x.end());
        int n_radios = 0;
        int N = x.size();
        int house = 0;
        int i = 0;
        while(i < N){
            house = x[i];  // radio installed here
            while(i < N && x[i] <= house + k){
                i ++;
            }
            n_radios ++;
            house = x[i-1];  // radio installed here
            while(i < N && x[i] <= house + k){
                i ++;
            }
        }
        return n_radios;