This is my CPP solution.
class Solution {
public:
string generateTheString(int n) {
string s;
if(n%2==0){
while(n-- > 1){
s.push_back('a');
}
s.push_back('b');
return s;
}
while(n--){
s.push_back('a');
}
return s;
}
};