• + 0 comments

    my code in javascript

    function gridSearch(G, P) {
        // Write your code here
        const n = G.length;
        const m = P.length;
        for (let i = 0; i <= n - m; i++) {
            // loop row
            for (let j = 0; j <= G[i].length - P[0].length; j++) {
                // loop P
                let check = true;
    
                for (let k = 0; k < m; k++) {
                    if (G[i + k].substring(j, P[0].length + j) !== P[k]) {
                        check = false;
                        break;
                    }
                }
                if (check) {
                    return "YES";
                }
            }
        }
        return "NO";
    }