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 :) ) to pass test cases change all 'int's to 'size_t'
size_t gridlandMetro( size_t const & _rows, size_t const & _columns, size_t const & _tracksTotalNum, std::vector<vector<size_t>> & _tracks ){ if(_tracks.empty()){ return _rows * _columns; }else if(_tracks.size() == 1){ return _rows * _columns - (_tracks.front().at(2) - _tracks.front().at(1) + 1); } std::sort(std::begin(_tracks), std::end(_tracks)); size_t lamps = _rows * _columns; for(auto current = std::begin(_tracks), next = current + 1; next < std::end(_tracks); ++current, ++next ){ if((*current).at(0) == (*next).at(0)){ if((*current).at(2) + 1 >= (*next).at(1)){ (*next).at(1) = (*current).at(1); if((*current).at(2) > (*next).at(2)){ (*next).at(2) = (*current).at(2); } }else{ lamps -= (*current).at(2) - (*current).at(1) + 1; } }else{ lamps -= (*current).at(2) - (*current).at(1) + 1; } if(next + 1 == std::end(_tracks)){ lamps -= (*next).at(2) - (*next).at(1) + 1; } } return lamps; }
Seems like cookies are disabled on this browser, please enable them to open this website
Gridland Metro
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 :) )
to pass test cases change all 'int's to 'size_t'