Longest Pallindromic Substring
Duration: 26 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- HPSC Interview Preparation: Interview Preparation
- Python Language: Introduction to Python Tokens, Variables, Data Types, I/O Operators & Expressions Control Flow & Looping Collections & Strings Functions & Modules File Handling & Data Analysis DSA using Python
- Data Structure & Algorithms: Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing Algorithm Analysis Sorting Algorithms Minimum Spanning Trees Time Complexity Analysis Graph Theory Shortest Path Algos
- Computer Networks: Introduction to CN Data Communication DLL: Access Control DLL: Flow Control Data Link Layer - Ethernet Net Layer: IPv4 & Proto Net Layer: IP Addressing Transport Layer Services TL: Congestion & UDP Application Layer Hardware basics Network Security
- Computer System & Organisation: Basics of COA Cache Memory Organization Input Output Organisation Pipelining Instr Formats & Modes Control Unit Design Programming the Basic Computer
- Database Management System: Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) Decomposition Properties & 4NF SQL File Organization & Indexing Transaction Management Concurrency Control
- Operating Systems: Introduction to OS Process Management CPU Scheduling Process Synchronization Deadlock Threads & Process Creation Memory Management Virtual Memory Disc Scheduling
- Digital Logic & Circuits: Digital Systems & Boolean Basics Logic Gates & Hardware Boolean Expression Boolean Minimization Combinational Circuit Sequential Circuits Number System Number Representation
- Theory Of Computation: Introduction to TOC Deterministic FA (DFA) Non-Deterministic FA Regular Expressions Grammar Regular Language Properties Pushdown Automata & CFG Turing Machines
- Compiler Design: Intro to Compilers Lexical Analysis Grammar & CFG Syntax Analysis: Top-Down Syntax Analysis: Bottom-Up Semantic Analysis & SDT Intermediate Code Gen Code Optimization Run Time Environment
- Software Engineering: Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management Data Warehousing & Mining
- Introduction to Emerging Trends: Emerging Trends and AI Sets, Relations, Functions and Discrete Mathematics Trade, Marketing and Consumer Protection Internet of Things Cloud Computing अनुक्रम, श्रेणी और संयोजन आव्यूह और रैखिक बीजगणित वास्तविक और सम्मिश्र विश्लेषण Mathematics Pedagogy International Economics Electrostatics and Current Electricity Optics and Photonics Folk Art and Crafts Analysis of Financial Statements Business Foundations and Entrepreneurship Number Systems and Number Theory Solid State Physics and Electronics Number System Multimedia Network Access Technologies
- Digital Society & Cyber Law: Society, Law & Ethics Teaching Aids and Educational Technology Digital India and Online Services Culture, Socialisation and Social Control Communication Contexts and Media Public Administration and Governance MS Office Applications Language Design Web Publishing & Hosting C Fundamentals Internet Fundamentals
- HPSC PGT Previous Year Paper:
- HPSC Assistant Professor Previous Year Paper:
- Live Sessions: HPSC Live Sessions EMRS TGT/PGT Live Class
- Full Mock Test:
- HPSC PGT - MOCK Test Series:
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This video is a comprehensive tutorial on solving the 'Longest Palindromic Substring' problem, a common algorithmic challenge. The instructor begins by presenting the problem statement from a coding platform, explaining that the goal is to find the longest substring within a given string that reads the same forwards and backwards. The core of the lesson is the 'Expand Around Center' algorithm, which is explained both conceptually and through a step-by-step implementation. The instructor uses a digital whiteboard to illustrate the method, showing how to treat each character (and each gap between characters) as a potential center of a palindrome and expand outwards to find the longest possible palindrome. This is followed by a detailed walkthrough of the Python code, where the `expand_around_center` function is defined to handle both odd-length (e.g., 'aba') and even-length (e.g., 'abba') palindromes. The main function iterates through each possible center, calls the helper function, and keeps track of the longest palindrome found. The video concludes with the instructor writing the complete, working code in an online IDE, demonstrating its execution and showing the accepted solution with performance metrics.
Chapters
0:00 – 2:00 00:00-02:00
The video opens on a coding platform, leetcode.com, displaying the problem '5. Longest Palindromic Substring'. The problem description, examples, and constraints are visible. The instructor explains the task: given a string, return the longest palindromic substring. The code editor on the right shows a skeleton of a Python class with a method `longestPalindrome` that takes a string `s` and returns a string. The instructor then transitions to a digital whiteboard to begin the explanation.
2:00 – 5:00 02:00-05:00
On the digital whiteboard, the instructor writes the problem title '26 Longest Palindromic Substring'. They introduce the core concept: 'Expand around centre'. Using the example string 'babad', they demonstrate how to treat each character as a potential center of a palindrome and expand outwards. They draw diagrams showing the expansion for the center at 'b' (resulting in 'bab') and at 'a' (resulting in 'aba'). They also illustrate the concept of even-length palindromes by showing the center between 'b' and 'a' in 'baab'.
5:00 – 10:00 05:00-10:00
The instructor continues on the whiteboard, explaining the algorithm in more detail. They write the pseudocode for the main function `longestPalindrome(s)` and the helper function `expand_around_center(left, right)`. They emphasize that the algorithm must handle both odd and even length palindromes by calling the helper function twice for each center: once with `i` and `i` (for odd), and once with `i` and `i+1` (for even). They write the logic for the `expand_around_center` function, which uses a while loop to expand as long as the characters at the left and right pointers are equal and within bounds.
10:00 – 15:00 10:00-15:00
The instructor completes the pseudocode on the whiteboard. They write the `expand_around_center` function, which returns the substring from `left` to `right` (inclusive). They then write the main loop of `longestPalindrome`, which iterates through each index `i` in the string. For each `i`, it calls `expand_around_center(i, i)` and `expand_around_center(i, i+1)`, compares the lengths of the resulting palindromes, and updates the `longest` variable if a longer one is found. They also write the base case for a single character string.
15:00 – 20:00 15:00-20:00
The instructor transitions back to the coding environment. They begin to write the actual Python code based on the whiteboard pseudocode. They define the `expand_around_center` function, which takes `left` and `right` indices and returns the substring. They implement the while loop to expand the palindrome, checking bounds and character equality. They then define the `longestPalindrome` function, initialize `longest` to an empty string, and loop through the string to find the longest palindrome by calling the helper function for both odd and even cases.
20:00 – 25:00 20:00-25:00
The instructor completes the code in the IDE. They write the logic to compare the lengths of the two palindromes found at each center and update the `longest` variable accordingly. They add a final return statement for the `longestPalindrome` function. The complete code is shown, and the instructor runs it, which results in an 'Accepted' status with a runtime of 276 ms and memory usage of 16.70 MB.
25:00 – 26:13 25:00-26:13
The video concludes with a final view of the accepted solution in the online IDE. The code is fully written and has passed all test cases. The instructor's final comment is to 'submit' the solution. The screen shows the accepted status, the runtime, and memory usage, confirming the successful implementation of the 'Expand Around Center' algorithm.
The video provides a clear, step-by-step guide to solving the Longest Palindromic Substring problem. It effectively combines a conceptual explanation using a whiteboard to illustrate the 'Expand Around Center' method with a practical implementation in Python. The instructor methodically breaks down the problem, first explaining the core idea of treating each character as a center, then detailing the code structure, and finally showing the complete, working solution. This approach ensures a deep understanding of both the algorithm's logic and its practical application, making it an excellent resource for learning this classic algorithmic challenge.

