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.
funcfindMultipleIndexes(str,substrstring)[]int{varindices[]intstart:=0for{index:=strings.Index(str[start:],substr)ifindex==-1{break}indices=append(indices,start+index)start+=index+1}returnindices}funcContains(M[]int,Itemint)bool{for_,v:=rangeM{ifv==Item{returntrue}}returnfalse}funcgridSearch(G[]string,P[]string)string{// Write your code hereconstNO="NO"constYES="YES"iflen(P)==0{return"NO"}row:=-1// find the first line of patter matchfori,v:=rangeG{cols:=findMultipleIndexes(v,P[0])for_,col:=rangecols{row=i// if next not lines available at the Groupifrow==-1||col==-1||len(G)<row+len(P){// return NOcontinue}found:=true// now check for next linesforj:=row+1;j<row+len(P);j++{i:=j-rowncols:=findMultipleIndexes(G[j],P[i])if!Contains(ncols,col){found=falsebreak}}iffound{returnYES}}}returnNO}
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 →
Golang: