1324. The Spreadsheet Column Name
Spreadsheet columns are named A to Z, then AA to AZ, then BA, and so
on. Given a column number, print its name.
1 -> A 26 -> Z 27 -> AA 28 -> AB 702 -> ZZ 703 -> AAA
This looks like conversion to base 26 and it is NOT, which is what makes it a real interview question rather than a lookup.
An ordinary base has a zero digit, so its digits run 0 to 25. This system has no
zero: the digits run A to Z, worth 1 to 26. After Z comes AA, where an
ordinary base would produce BA after a digit wrapped to zero.
The repair is one line, and where it goes matters:
while n > 0:
n = n - 1 <-- shift into 0..25 BEFORE taking the remainder
append letter 'A' + n % 26
n = n / 26
Subtracting 1 first maps 1..26 onto 0..25, so the remainder indexes the alphabet
and the division carries correctly. Doing it after the remainder, or not at all,
gives A@ for 27, and that single misplaced line is the entire problem.
Constraints - `1 ≤ n ≤ 1000000`
Input
One line containing the column number n.
Output
Print the column name, in capitals.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.