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.
boolis_present(vector<string>&G,vector<string>&P,inti,intj){intP_row=P.size();intP_col=P[0].size();for(intp=0;p<P_row;++p){for(intk=0;k<P_col;++k){if(G[p][k]!=P[p+i][k+j]){returnfalse;}}}returntrue;}stringgridSearch(vector<string>G,vector<string>P){intP_row=P.size();intP_col=P[0].size();intG_row=G.size();intG_col=G[0].size();for(inti=0;i<=G_row-P_row;++i){for(intj=0;j<=G_col-P_col;++j){// Check if the pattern starts at position (i, j)boolflag=true;for(intp=0;p<P_row;++p){for(intk=0;k<P_col;++k){if(P[p][k]!=G[p+i][k+j]){flag=false;break;}}if(!flag)break;}// If the pattern is found, return "YES"if(flag)return"YES";}}// If the pattern is not found at any position, return "NO"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 →