The Complete Solution provided here prepends a char to a string for every iteration. Prepending is O(n), it’s better to reverse the whole string at the end.
That is correct Felipe. A better way would be to append and reverse at the end.
Anshuman Singh not only better but “right” if the interviewer is expecting a linear solution. I looked at the solution because I never know the best way to approach these kind of problems: (a) calculate the right index and build the string as it should be; and (b) build the string and reverse at the end.
Felipe Carvalho True, if the problem was intended for converting big Integers to Excel sheet number.
Note that the domain is limited to positive integers which fit in an int here. For such inputs, the differentiation between O(n) and O(n^2) is irrelevant.
If the big Integer were to come into the picture, the string prepend / append would hardly be the bottleneck step.