Excel Column Number
Easy About 8 min Free, no account needed
Spreadsheet columns are base-26 with no zero digit.
The brief
Spreadsheet columns are lettered A, B, ..., Z, AA, AB, .... Given a column
title, return its 1-based number (A=1, Z=26, AA=27).
Columns look like base-26, but there is no zero digit: A is 1, Z is
26, and AA follows Z rather than BA, so a lookup table built for
ordinary base-26 is off by one at every position. The hidden tests reach
FXSHRXW (int.MaxValue), where reconstructions that pass through
floating point (Math.Pow) start to wobble by one. Stay in exact integer
arithmetic.
Starter code
using System;
public class Solution
{
// TODO: return the 1-based column number for an Excel column title.
public long TitleToNumber(string column)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- Math and number theory
- Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.
- Multiply Numeric Strings Medium Free Schoolbook multiplication of numbers thousands of digits long.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.