Convert Excel Column Title to Number

Duration: 7 min

This video lesson is available to enrolled students.

Return to /learn/COGNIZANT-PREPARATION/technical-assessment/coding-questions/coding-question/asset-convert-excel-column-title-to-number after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Communication Round: Vocabulary, Subject Verb Agreement (Verb Noun Agreement), Tenses, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Cloze Test (Cloze Passage), Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Direct and Indirect Speech, Active Passive Voice (Voice), Verbal Analogy (Word Based Analogy), Articles, Preposition, Conjunction, Sentence Construction, English Writing Ability, Communication Assessment
  2. Quantitative Aptitude: Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Time and Work, Mensuration and Geometry, Age Problems, Pipe and Cistern, Probability, Profit and Loss, Simple Interest and Compound Interest, Algebra
  3. Analytical and Logical Reasoning: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Directions (Direction Test), Ranking, Order and Sequence, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Selection Decision Table (Decision Making), Logical Sequence Of Words, Puzzle Solving (Puzzles), Syllogisms, Seating Arrangements, Calendar, Clock, Blood Relations, Cubes & Dices, Venn Diagram, Analytical Reasoning (Counting Figures Reasoning)
  4. Cognizant Gaming Aptitude: Gamified / Game Based Aptitude
  5. Java (Cluster 1): Java
  6. ANSI SQL MySQL (Cluster 1,2,3): SQL
  7. HTML, CSS, JavaScript (Cluster 1,3): HTML, CSS, JavaScript
  8. Python (Cluster 2): Python for Placements by Yash Sir
  9. Cloud Fundamentals (Cluster 2): Emerging Tech Trends
  10. C# (Cluster 3): C#
  11. OOPs: Object Oriented Programming (OOPS)
  12. Technical Assessment (Coding): Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Pseudo Codes
  13. Data Structures: Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  14. DBMS: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, Relational Calculus, Transaction Management, Concurrency Control, Database Recovery, ORDBMS, Database Security & Authorization, Query Processing & Optimization, Enhanced Data Models, Data Warehousing & Mining, Big Data Systems, NoSQL
  15. Operating Systems: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS, Linux OS, Security, Distributed Systems, Virtual Machines
  16. Computer Networks: Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics, Network Security, Mobile Technology, Cloud Computing and IoT, Cyber and Info Security
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…