Convert Excel Column Title to Number

Duration: 7 min

This video lesson is available to enrolled students.

Return to /learn/TCS-NQT-PREPARATION/advanced-coding/coding-questions/coding-question/asset-convert-excel-column-title-to-number after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. TCS One Shot Free Videos & Notes: TCS Preparation
  2. Numerical Ability (Foundation Section): Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Algebra, Probability, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Mensuration and Geometry, Mental Ability, Age Problems, Statistics, Arithmetic, Partnership, Speed Mathematics and Basic Mathematics
  3. Reasoning Ability (Foundation Section): Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Directions (Direction Test), Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Calendar, Clock, Cubes & Dices, Selection Decision Table (Decision Making), Crypt Arithmetic, Venn Diagram, Data Arrangement, Inequality, Analogy, Ranking, Order and Sequence, Logical Sequence Of Words
  4. New Pattern-Verbal Ability (Foundation Section): Sentence Completion (Fill in the blanks), English Writing Ability
  5. Old Pattern-Verbal Ability (Foundation Section): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Articles, Direct and Indirect Speech, Conjunction, Modals, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Verbal Analogy (Word Based Analogy), Active Passive Voice (Voice), Determiner, Facts, Inference and Judgements, Adverb, Cloze Test (Cloze Passage), Sentence Construction, Verb
  6. Advanced Quantitative Ability: TCS NQT Advanced Quantitative Ability
  7. Advanced Reasoning Ability: TCS NQT Advanced Reasoning Ability
  8. Advanced Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Python for Placements by Yash Sir, DSA using Python, Object Oriented Programming (OOPS), Programming in C++, Java
  9. TCS Full Length Mock Test:
  10. TCS Interview & Resume Prep: MR & HR Interview Preparation, TCS Interview Preparation, Mock Interview, Interview Recordings, Resume Preparation, Resume Review
  11. Mega Test:
  12. Grand Test:
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This educational video from Knowledge Gate provides a comprehensive tutorial on solving a programming problem related to converting an Excel column title to its corresponding column number. The lecture begins by defining the problem: given a string representing an Excel column title (e.g., 'A', 'AA', 'AAA'), find the integer that represents that column. The core of the video is a step-by-step derivation of the algorithm, which is based on a base-26 number system where 'A' represents 1, 'B' represents 2, and so on, up to 'Z' representing 26. The instructor uses a chalkboard to demonstrate the mathematical logic, showing that for a string like 'AA', the calculation is (1 * 26) + 1 = 27. This is generalized into a formula: result = 26 * result + (s[i] - 'A' + 1). The video then transitions to a code implementation in C, showing a function `titleToNumber` that iterates through the string, applying this formula to build the final column number. The lesson is reinforced with multiple worked examples, including the conversion of 'A' to 1, 'AA' to 27, and 'AAC' to 705, which are shown on the board and in the code.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The video opens with the Knowledge Gate logo, followed by a slide that introduces the problem. The problem statement is displayed on a whiteboard, which reads: 'Given a string S that represents column title of an Excel sheet, find the number that represents that column. In excel A column is number 1, AA is 27 and so on.' The constraints are listed as 1 ≤ |S| ≤ 7. The input is a single line containing string S, and the output is the column number. An example is provided: Input 'A' outputs 1, and Input 'AA' outputs 27. The instructor, Yash Jain Sir, is visible in a small window, and the video is marked as a copyright of Knowledge Gate Eduventures.

  2. 2:00 – 5:00 02:00-05:00

    The instructor explains the pattern of Excel column titles, which is a base-26 system. He writes on the chalkboard that column 1 is 'A', column 2 is 'B', ..., column 26 is 'Z', column 27 is 'AA', and so on. He provides a table of examples, showing that 26 maps to 'Z', 51 to 'AY', 52 to 'AZ', 80 to 'CB', 676 to 'ZZ', and 705 to 'AAC'. He then begins to derive the formula for the conversion, writing 'Z -> 26' and 'AA -> 27'. He explains that the first 'A' in 'AA' is in the 26's place, so the calculation is (1 * 26) + 1 = 27. He continues to break down the logic for 'AAC', showing that it is (1 * 26^2) + (1 * 26^1) + (3 * 26^0) = 676 + 26 + 3 = 705. He emphasizes that the formula is 'result = 26 * result + (s[i] - 'A' + 1)'.

  3. 5:00 – 6:41 05:00-06:41

    The video transitions to a code implementation. A code editor window displays a C function `int titleToNumber(char s[])`. The function initializes an integer `result` to 0. A for loop iterates through each character of the string `s`. Inside the loop, the formula `result = result * 26 + s[i] - 'A' + 1;` is applied. The instructor explains that this formula is derived from the base-26 logic. He then shows the function returning the final `result`. The video concludes by revisiting the examples on the board, confirming that the code correctly handles inputs like 'A' (output 1) and 'AA' (output 27), reinforcing the connection between the mathematical concept and its programming implementation.

The video presents a clear, structured lesson on a classic programming problem. It effectively bridges the gap between a real-world application (Excel column naming) and its underlying mathematical algorithm. The teaching progression moves logically from problem definition to conceptual understanding (base-26 system) to algorithmic derivation (the formula) and finally to practical implementation (the C code). The use of a chalkboard for step-by-step calculations and a code editor for the final solution provides a comprehensive learning experience, making the abstract concept of number systems tangible for students.

Loading lesson…