codejump
EasyPro challengePythonJavaScriptTypeScript

Math — Excel Sheet Column Title

AlgorithmsMathStrings

solve(columnNumber) — convert a positive column number (1 <= columnNumber < 2^31) to its
spreadsheet title: 1 → "A", 26 → "Z", 27 → "AA", 28 → "AB", 702 → "ZZ", 703 → "AAA".

It looks like base 26, but it is bijective: there is no digit for zero (A is 1, Z is
26). The usual n % 26 loop breaks on multiples of 26. The fix is to shift by one before
each division: take the letter for (n - 1) % 26, then continue with floor((n - 1) / 26).

Examples

solve(1)      → "A"
solve(28)     → "AB"
solve(701)    → "ZY"
solve(52)     → "AZ"

Sample tests

Test #1First column
Input: [1]
Output: "A"
Test #2Two letters
Input: [28]
Output: "AB"
Test #3Near ZZ
Input: [701]
Output: "ZY"