Longest Pallindromic Substring

Duration: 26 min

This video lesson is available to enrolled students.

Return to /learn/BIHAR-STET-COMPUTER-SCIENCE-COMPLETE-COURSE/unit-16-python/dsa-using-python/strings/asset-longest-pallindromic-substring after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. About the course: About the Course
  2. Mathematical Aptitude: Number System, HCF LCM, Divisibility Rules, Percentage, Ratio and Proportion (Ratios), Average, Profit and Loss, Time and Work, Mensuration and Geometry, Simple Interest and Compound Interest, Speed Time and Distance, Age Problems, Mixture and Alligation, Algebra, Powers and Exponents (Surds and Indices), Pipe and Cistern, Trigonometry, Statistics, Data Interpretation, Arithmetic
  3. Logical Reasoning: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Analogy, Blood Relations, Directions (Direction Test), Ranking, Order and Sequence, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Seating Arrangements, Syllogisms, Venn Diagram, Puzzle Solving (Puzzles), Logical Sequence Of Words, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Analytical Reasoning (Counting Figures Reasoning), Cubes & Dices, Calendar, Clock
  4. General Knowledge: Physics, Chemistry, Biology, History, Geography, Polity, Indian Economy, GK- Current Affairs, Static General Knowledge
  5. Art of Teaching: Nature, Objectives & Characteristics of Teaching, Learners & Learning Process, Factors Affecting Teaching, Methods of Teaching, Classroom Management & Communication, Teaching-Learning Aids & ICT Integration, Evaluation, Assessment & Measurement, Professional Development & Ethics, Policies, Acts & Contemporary Issues, Curriculum & School Environment, Guidance, Counselling & Mental Health, Inclusive Education & Special Needs, Micro-Teaching & Teaching Skills, Lesson Planning
  6. Environmental Science: Environment
  7. Unit 1 | Digital Electronics: Digital Systems & Boolean Basics, Logic Gates & Hardware, Boolean Expression, Boolean Minimization, Combinational Circuit, Sequential Circuits, Number System, Number Representation
  8. Unit 2 | COA: Basics of COA, Floating Point Rep, Cache Memory Organization, Input Output Organisation, Instr Formats & Modes, Control Unit Design, Register Transfer and Microoperations, Programming the Basic Computer
  9. Unit 3 | C Programming: C Fundamentals, Control Flow, Functions, Arrays & Pointers, Storage Classes, Structures & Enums, DMA, Macros, Scoping & File Handling
  10. Unit 3 | Data Structures: Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  11. Unit 4 | Algorithms: Algorithm Analysis, Time Complexity Analysis, Sorting Algorithms, Dynamic Programming, Minimum Spanning Trees, Shortest Path Algos, Advanced Algorithms
  12. Unit 5 | Operating System: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Threads & Process Creation, Deadlock, Memory Management, Virtual Memory, Disc Scheduling, File Management
  13. Unit 6 | Database Management System: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, SQL, Transaction Management, Concurrency Control
  14. Unit 7 | 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
  15. Unit 8 | Software Engineering: Fundamentals of Software Engineering, Software Requirements and Quality Assurance, Software Design, Estimation and Metrics, Software Testing, Software Maintenance and Configuration Management
  16. Unit 9 | Object Oriented Programming: OOPS with C++
  17. Unit 10 | Web Development: HTML Basics, CSS, JavaScript-Basics, XML
  18. Unit 11 | Theory Of Computation: Introduction to TOC, Deterministic FA (DFA), Non-Deterministic FA, Regular Expressions, Grammar, Regular Language Properties, Moore & Mealy Machines, Pushdown Automata & CFG, Turing Machines
  19. Unit 12 | IoT: Emerging Tech Trends, Cloud Computing
  20. Unit 13 | Artificial Intelligence: Approaches to AI, Search Algorithms, Game Playing, Knowledge Representation, Natural Language Processing, Artificial Neural Networks, Genetic Algorithms
  21. Unit 14 | E-Commerce: Electronic Data Interchange and E-Commerce, Role of Internet and Web Services, Security in Mobile and Wireless Computing, Physical Security and Cryptography Basics, Cyber Safety and Security
  22. Unit 15 | Multimedia: Multimedia
  23. Unit 16 | Python: 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
  24. Full Length Mock Tests — General Paper:
  25. Full Length Mock Tests — Computer Science (Paper II):
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

  1. 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. 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'.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Loading lesson…