2 C++ Solutions || Different Methods each time for replacement of '?' || Most Optimized Approach
Approach 1\nIn this approach when we encounter a \'?\' we try from the first character \'a\', if the character satisfies the condition of the question i.e. not 
**Approach 1**\nIn this approach when we encounter a \'?\' we try from the first character \'a\', if the character satisfies the condition of the question i.e. not similar to the consecutive one, then we replace the ? with the character, otherwise we increment the current char try doing the same as we did with a.\n```\nclass Solution {\npublic:\n    string modifyString(string s) {\n        \n        for(int i = 0; i<s.size(); i++){\n            if(s[i] == \'?\'){\n                char x = \'a\';\n                if(i == 0){\n                    while(x == s[i+1]){\n                        x++;\n                    }\n                }\n                \n                else if(i == s.size()-1){\n                    while(x == s[i-1]){\n                        x++;\n                    }\n                }\n                \n                else{\n                    while(x==s[i-1] or x == s[i+1]){\n                        x++;\n                    }\n                }\n                \n                s[i] = x;\n            }\n        }\n        \n        return s;\n\t    }\n};\n```\n\n**Approach 2: We need only 3 variables for the replacement of ?**\nLet us assume we have taken three variables as a, b and c.\n\nWhenever there is a ? there are three cases:\n1. Both the left and right of ? consist of a then we can insert b\n2. Both the left and right consist of alphabet other than a then we can insert a\n3. Left side contain a and right side contain b, then we can insert third variable c.\n```\nclass Solution {\npublic:\n    string modifyString(string s) {\n        \n        int n = s.size();\n        \n        for(int i = 0; i<n; i++){\n            \n            if(s[i] == \'?\'){\n    //for the ? to be present at the first index there is only one case which is that next element must not be the same\n                if(i == 0){\n                    //if the next element is not a then insert a to current position \n                    if(s[i+1] != \'a\'){\n                        s[i] = \'a\';   \n                    }\n                    \n                    //if the next element is a then insert b to current position \n                    else{\n                        s[i] = \'b\';\n                    }\n                }\n                \n    //for the ? to be present at the last index there is only one case which is that previous element must not be the same\n                else if(i == n-1){\n                    //if the previous element is not a then put a to current index\n                    if(s[i-1] != \'a\'){\n                        s[i] = \'a\';\n                    }\n                    //if the previous element is a then put b to current index\n                    else{\n                        s[i] = \'b\';\n                    }\n                }\n                \n                else{\n                    if(s[i-1] != \'a\' and s[i+1]!=\'a\'){\n                        s[i] = \'a\';\n                    }\n                    \n                    else if(s[i-1] != \'b\' and s[i+1]!=\'b\'){\n                        s[i] = \'b\';\n                    }\n                    \n                    else{\n                        s[i] = \'c\';\n                    }\n                    \n                }\n            }\n        }\n        \n        return s;\n    }\n};\n```
['C', 'C++']