Words Within Two Edits of Dictionary

PHOTO EMBED

Sat Oct 29 2022 17:33:58 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    vector<string> twoEditWords(vector<string>& q, vector<string>& d) {
        int n1=d.size();
        int n2=q.size();
        int k=q[0].size();
        vector<string>v;
        set<int> idx;
        for(int i=0;i<n2;i++)
        {
            for(int j=0;j<n1;j++)
            {
                int c=0;
                for(int h=0;h<k;h++)
                {
                    if(d[j][h]!=q[i][h]) c++;
                }
                if(c<=2) idx.insert(i);
            }
        }
        for(auto x:idx)
        {
           v.push_back(q[x]) ;
        }
        return v;
    }
};
content_copyCOPY

https://leetcode.com/contest/biweekly-contest-90/problems/words-within-two-edits-of-dictionary/