• + 0 comments

    Here is my solution in PHP

        $prows = count($P);
        $grows = count($G);
        $firstRow = array();
        $firstIndex = array();
        
        $result = 'NO';
        for ($i=0; $i <=$grows-($prows-1) ; $i++) { 
            $rowIndex = array();
            $offset = 0;
            while(($str = strpos($G[$i], $P[0],$offset))!== false)
            {
                $rowIndex[] = $str;
                $offset = $str+1;
    
            }
            $firstRow[$i] = $rowIndex;
        }
    
     
         foreach ($firstRow as $key => $value) {
             // code...
            if($result == 'YES')
            {
                break;
            }
            if($grows - ($key) >= $prows)
            {
                foreach ($value as $key1 => $value1) {
                     $keyIndex =  $value1;
                     $newKey = 0;
                     $lastIndex = $key+$prows-1;
                    
                          for ($i=$key+1; $i <($key+$prows) ; $i++) { 
                             
                          $newKey+=1;
                          
                          $str = strpos($G[$i], $P[$newKey],$value1);
                         
                    if ($str !== false && $str == $keyIndex) {
                            if($i == $lastIndex)
                             {
                               $result = 'YES';
                                break;
                             }
                    }
                   else
                   {
                    break;
                   }
    
                 
               }
               
                }
             
             
       
            }
            else
            {
                continue;
            }
         }    
     return $result;