Solution using unordered map C++
\nclass Solution {\npublic:\n    //\n    int mod=1e9+7;\n    char arr[3]={\'R\',\'B\',\'G\'};\n    vector<string>v;\n    unordered_map<string,int>ans;\n    void
```\nclass Solution {\npublic:\n    //\n    int mod=1e9+7;\n    char arr[3]={\'R\',\'B\',\'G\'};\n    vector<string>v;\n    unordered_map<string,int>ans;\n    void get_v(int m, string s)\n    {\n        if(m==0)\n        {\n            v.push_back(s);\n            return;\n        }\n        char ch=\'$\';\n        if(s.size()>=1)\n        ch=s[s.size()-1];\n        for(int i=0;i<3;i++)\n        {\n            if(arr[i]!=ch)\n                get_v(m-1,s+arr[i]);\n        }\n        \n    }\n    void recur(int curr,int n)\n    {\n        if(curr==n+1)\n            return;\n        unordered_map<string,int>newans;\n        for(int i=0;i<v.size();i++) // our current ending\n        {\n            for(int j=0;j<v.size();j++) // checking wiht all prev endings\n            {\n                int fl=1;\n                for(int l=0;l<v[i].size();l++)\n                {\n                    if(v[i][l]==v[j][l])\n                    {\n                        fl=0;\n                        break;\n                    }\n                }\n                if(fl)\n                {\n                    newans[v[i]]+=ans[v[j]];\n                    newans[v[i]]%=mod;\n                    // cout<<v[i]<<" "<<v[j]\n                }\n            }\n        }\n        ans=newans;\n        recur(curr+1,n);\n    }\n    int colorTheGrid(int m, int n) {\n        get_v(m,"");\n        cout<<v.size()<<"\\n";\n        for(auto it:v)\n            ans[it]=1;\n        recur(2,n);\n        int myans=0;\n        for(auto it:v)\n        {\n            myans+=ans[it];\n            myans%=mod;\n        } \n        return myans;\n    }\n};\n```
[]