Convert a number to an Excel column, and convert an Excel column back to a number.
In Excel, columns are labeled as:
- 1 →
"A" - 2 →
"B" - …
- 26 →
"Z" - 27 →
"AA" - 28 →
"AB" - …
You are asked to implement two functions:
- Given a positive integer, convert it to its corresponding Excel column title (e.g.,
1 -> "A",28 -> "AB"). - Given an Excel column title (string of uppercase letters), convert it back to its corresponding number (e.g.,
"A" -> 1,"AB" -> 28).
You may assume:
- The integer input is positive
- The column title consists of only uppercase letters
A–Z
- Number → Column: treat it as a 26-base system without zero; repeatedly do
n--, take(n % 26)to map0..25→A..Z, thenn /= 26. - Column → Number: scan from left to right, accumulate like normal base-26:
res = res * 26 + (ch - 'A' + 1).
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.