Convert a Column Number to an Excel-Style Label
HouzzSoftware Engineer · Online AssessmentLast updated
Convert one-based spreadsheet columns into A-through-Z and AA-through-ZZ labels, with correct handling of multiples of 26.
Convert a one-based spreadsheet column number into its Excel-style column label. Columns 1 through 26 are A through Z; column 27 is AA, and the sequence continues through ZZ at column 702.
Implement column_label(n: int) -> string and return the label as an uppercase string.
Constraints & Assumptions
nis an integer in the inclusive range 1 through 702.- This is a column label only; do not append a row number.
- The numbering is one-based. There is no zero digit and no label for column zero.
- The input is valid; error handling for out-of-range values is outside this callable's contract.
Examples
column_label(26)returns"Z".column_label(27)returns"AA".
Hints
Hint 1
Account for the missing zero digit: Before taking a remainder by 26, align the current one-based position with the zero-based offsets used to select letters from A through Z.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.