Excel Sheet Column Title
Excel Sheet Column Title 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.
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
- String Manipulation Patterns pattern guide
- Integer and Roman Conversion subpattern
- The full DSA patterns sheet
- All coding practice problems
Problems related to Excel Sheet Column Title
Other problems that use the same Integer and Roman Conversion and String Manipulation Patterns techniques:
- Integer to Roman — Medium, same subpattern
- Roman to Integer — Easy, same subpattern
- String to Integer (atoi) — Medium, same subpattern
- Add Strings — Easy, same pattern
- Find Beautiful Indices in the Given Array II — Hard, same pattern
- Find the Index of the First Occurrence in a String — Easy, same pattern