The idea behind this problem is as follows:

Consider getting the characters for 28: It's 26^1 * (first Character) + 26^0 * (second Character), which in this case is 26*'A' + 1*'B' . Therefore to get the last character mod by 26. Then to get the character prior to that divide by 26 then mod by 26 and so on till what remains is zero.

```
string convertToTitle(int n) {
string res="";
while(n>0){
res=char('A'+(n-1)%26)+res;
n=(n-1)/26;
}
return res;
}
```