We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This should be easy in my opinion, because a O(n2) can handle the input conditions. (Not a large number)
stringgridSearch(vector<string>G,vector<string>P){// For every occurrence of P[0][0], determine if it's a match.charstamp_cursor=P[0][0];for(size_tx(0);x<G.size();++x){for(size_ty(0);y<G[0].size();++y){if(G[x][y]==stamp_cursor){// Compare the rest.if(x+P.size()>G.size())continue;// out of bound.if(y+P[0].size()>G[0].size())continue;// out of bound.for(size_ti(0);i<P.size();++i){for(size_tj(0);j<P[0].size();++j){if(G[x+i][y+j]!=P[i][j])gotoCONTINUE_LABEL;// not a match.}}// Passed all the tests. It's a match!return"YES";}CONTINUE_LABEL:;}}return"NO";}
Cookie support is required to access HackerRank
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 →
This should be easy in my opinion, because a O(n2) can handle the input conditions. (Not a large number)