168. Excel Sheet Column Title

Excel Sheet Column Title (LeetCode 168) is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the String Manipulation Patterns pattern, in the Integer and Roman Conversion subpattern.

How to solve Excel Sheet Column Title

Excel Sheet Column Title is a Integer to Roman Numeral Conversion problem, part of String Manipulation Patterns. Learn to convert between integers and Roman numerals. Essential string manipulation problem.

Work towards the solution in these steps:

  1. Consider how ordinary base conversion would work if the available symbols were the letters `A` through `Z`.
  2. There is no symbol for zero, so adjust the number before extracting each letter.
  3. Extract letters from right to left, then reverse their order before returning the result.

The reference solution runs in O(log_26(columnNumber)) time and O(log_26(columnNumber)) space.

The Excel Sheet Column Title solution and editorial walks through the full approach with reference code.

Problem statement

A spreadsheet column label is formed from uppercase English letters, with A representing 1, B representing 2, and so on through Z representing 26. After Z, the sequence continues with two-letter labels such as AA, then AB, using the same ordering without a zero-valued digit.

Given the positive integer columnNumber, determine the label of that spreadsheet column. Return the corresponding label as a string.

Implement convertToTitle in the Solution class with the provided signature.

Example 1:

Input: columnNumber = 26 Output: "Z" Explanation: The 26th column is the last single-letter column, so its label is Z.

Example 2:

Input: columnNumber = 54 Output: "BB" Explanation: After Z, the labels continue with AA, ..., AZ, then BA, BB; therefore column 54 is BB.

Example 3:

Input: columnNumber = 1000 Output: "ALL" Explanation: Converting the number using the spreadsheet's one-based letter system produces the three-letter label ALL.

Constraints:

- 1 <= columnNumber <= 10^5 - columnNumber is an integer. - columnNumber is positive. - The returned label contains only uppercase English letters.

Topics and companies

Topics: Math, String, Iteration.

How to practise Excel Sheet Column Title on Thita.ai

Starter code is provided in C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(log_26(columnNumber)) time and O(log_26(columnNumber)) space.

Open Excel Sheet Column Title in the code editor, or read the Excel Sheet Column Title editorial for a worked solution with its approach and complexity analysis.

Where Excel Sheet Column Title sits in the DSA pattern sheet

Problems related to Excel Sheet Column Title

Other problems that use the same Integer and Roman Conversion and String Manipulation Patterns techniques:

Excel Sheet Column Title FAQ

What is the LeetCode number of Excel Sheet Column Title?

Excel Sheet Column Title is LeetCode problem 168, rated Easy.

What pattern is used to solve Excel Sheet Column Title?

Excel Sheet Column Title is a Integer to Roman Numeral Conversion problem. It belongs to the String Manipulation Patterns pattern, in the Integer and Roman Conversion subpattern.

What is the time complexity of Excel Sheet Column Title?

The reference solution runs in O(log_26(columnNumber)) time and O(log_26(columnNumber)) space.

Preparing this workspace.