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.
funcgridSearch(G:[String],P:[String])->String{// Write your code herevarpIndex:Int=0vargIndex:Int=0varprevIndex:Int=-1varset=Set<Character>()while(gIndex<=G.count-1){ifletranged=G[gIndex].range(of:P[pIndex],options:.regularExpression){letindex:Int=G[gIndex].distance(from:G[gIndex].startIndex,to:ranged.lowerBound)ifprevIndex!=-1&&prevIndex!=index{letsqueezed:String=G[gIndex-1].filter{set.insert($0).inserted}ifsqueezed.count!=1{pIndex=0prevIndex=-1continue}}ifpIndex==P.count-1{break}ifpIndex<P.count-1{pIndex+=1}ifprevIndex==-1{prevIndex=index}}elseif(pIndex!=0){pIndex=0continue}gIndex+=1}returnpIndex==P.count-1?"YES":"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 →
swift using built in regex