Longest Palindromic Substring

A Quick Overview

Problem Statement

Given a string, we have to find the longest palindromic substring. Substring is a sequence of characters that is contiguous within a string.


Input: findnitianhere  Output: indni  Explanation: Substring from index 1 to 5 is longest substring.

Find all the substrings from a string that are possible, and determine whether or not they are palindromes.

Simple Approach

Time complexity: O(N^3), where N is string size.  Space complexity: O(1)

How to implement Simple approach in different programming languages?

Efficient Approach: Dynamic Programming

Identify some patterns in validating palindromes to avoid unnecessary re-computation and improve brute force methods by memorizing the data.

Time complexity: O(N^2), where N is string size  Space complexity: O(N^2)

How to implement these approaches in different programming languages?