Convert Between Excel Column Labels and Column Numbers
Last updated: November 29, 2026
Quick Overview
Write two functions: one converts an Excel column label such as "AB" to its 1-based column number, and the other converts a column number back to its label.
Microsoft
November 29, 20260
0
0 solved
Write two functions: one converts an Excel column label such as "AB" to its 1-based column number, and the other converts a column number back to its label.
A warm-up in Microsoft online assessments and phone screens, fitting naturally since Excel's grid uses exactly this scheme up to column XFD. The interviewer wants to see that you recognize bijective base 26 (there is no zero digit) and handle the off-by-one cleanly instead of patching it with special cases for Z.
What the Interviewer Expects
- Recognizes the scheme is base 26 without a zero digit
- Handles the Z / AA boundary with a single decrement instead of special cases
- Validates input characters and ranges
- Tests round trips at boundaries like 26, 27, 702, 703, and 16384
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you parse a full cell reference like "$AB$12" into row and column?
- How would you convert an A1 range like "B2:D10" into the list of cells it covers?
- What changes if labels can be lowercase or the grid has a maximum column?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Labels are uppercase strings: A is 1, Z is 26, AA is 27, ZZ is 702, AAA is 703. Excel's last column XFD is 16384. Both directions must round-trip, and invalid input (empty label, lowercase, digits, n ...
High-Level Design
Reading a label is Horner's rule with digits 1 through 26: n = n * 26 + digit. Writing is the trap. Ordinary base 26 has digits 0 through 25, but here there is no zero, so 26 must become Z rather ...