Https://www.interviewbit.com/problems/excel-column-title/?ref=similar_problems#

programming
Tags: #<Tag:0x00007f181ccceff8>

#1

I can’t get what is wrong. In one or two test cases it’s giving slightly wrong answer.

string Solution::convertToTitle(int A) {
vector a;
while(A)
{ if(A%26) a.push_back(‘A’+A%26 -1 );
else a.push_back(‘Z’);
A=A/26;
}
int N=a.size();
char *t=new char[N];
for(int i=N-1; i>=0; i–)
t[N-1-i]=a[i];
return t;

}


#2

Got it.
string Solution::convertToTitle(int A) {
vector a;
while(A)
{ if(A%26) a.push_back(‘A’+ A%26 -1 );
else {a.push_back(‘Z’);A=A-26;} //the correction
A=A/26;
}
int N=a.size();
string t;
for(int i=N-1; i>=0; i–)
t.push_back(a[i]);
return t;
}


#3

i am getting error in line vector a