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:) )
inline std::vector<size_t> fndMatches( std::string const & _str, std::string const & _pttrn ){ using namespace std; auto idxMatch = _str.find(_pttrn); auto matches = vector<size_t>(); while(idxMatch != string::npos){ matches.emplace_back(idxMatch++); idxMatch = _str.find(_pttrn, idxMatch); } return matches; } std::string gridSearch( std::vector<std::string> const & _mtrx, std::vector<std::string> const & _pttrn ){ using namespace std; auto matchesIntersection = vector<size_t>(_mtrx.front().size(), numeric_limits<size_t>::max()); for(auto rowM = cbegin(_mtrx); rowM != cend(_mtrx); ++rowM){ auto matches = ::fndMatches(*rowM, _pttrn.front()); if(matches.empty()){ continue; } copy(cbegin(matches), cend(matches), begin(matchesIntersection)); for(auto rowMCopy = rowM, rowP = cbegin(_pttrn); rowMCopy != cend(_mtrx) && rowP != cend(_pttrn); ++rowMCopy, ++rowP ){ auto matchesNext = ::fndMatches(*rowMCopy, *rowP); auto itEnd = set_intersection( cbegin(matchesIntersection), cend(matchesIntersection), cbegin(matchesNext), cend(matchesNext), begin(matchesIntersection)); if(itEnd == begin(matchesIntersection)){ break; } if(rowP == --cend(_pttrn)){ return "YES"; } } } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Grid Search
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:) )