You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) ) time complexity O(n + (max(x) - min(x)), where 'n' and 'x' are described in the problem
int hackerlandRadioTransmitters( std::vector<int> const & _houseLocations, int const & _range ){ size_t const coverageArea = _range * 2 + 1; auto houseLocations = std::vector<bool>(std::pow(10,5) + 1, false); auto lastLocation = 0; auto firstLocation = static_cast<int>(std::pow(10,5)); for(auto const & location: _houseLocations){ firstLocation = std::min(firstLocation, location); lastLocation = std::max(lastLocation, location); houseLocations.at(location) = true; } size_t transmitters = 0; for(auto first = std::cbegin(houseLocations) + firstLocation; first < std::cbegin(houseLocations) + lastLocation + 1; ++first ){ if(!*first){ continue; } ++transmitters; if(*(first + _range)){ std::advance(first, coverageArea - 1); }else{ first = find_end(first, first + _range, first, first + 1); std::advance(first, _range); } } 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 →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) ) time complexity O(n + (max(x) - min(x)), where 'n' and 'x' are described in the problem