From c46e05e4586861bc30a48322d4861e402bb00ebe Mon Sep 17 00:00:00 2001
From: ImmidiSivani <147423543+ImmidiSivani@users.noreply.github.com>
Date: Sat, 27 Jul 2024 09:21:56 +0530
Subject: [PATCH] added solution to 647
---
.../0600-0699/647-palindromic-substrings.md | 182 ++++++++++++++++++
1 file changed, 182 insertions(+)
create mode 100644 dsa-solutions/lc-solutions/0600-0699/647-palindromic-substrings.md
diff --git a/dsa-solutions/lc-solutions/0600-0699/647-palindromic-substrings.md b/dsa-solutions/lc-solutions/0600-0699/647-palindromic-substrings.md
new file mode 100644
index 000000000..0b4e21f53
--- /dev/null
+++ b/dsa-solutions/lc-solutions/0600-0699/647-palindromic-substrings.md
@@ -0,0 +1,182 @@
+---
+id: palindromic-substrings
+title: Palindromic Substrings
+sidebar_label: 647-Palindromic Substrings
+tags:
+ - String Manipulation
+ - Dynamic Programming
+ - LeetCode
+ - Java
+ - Python
+ - C++
+description: "This is a solution to the Palindromic Substrings problem on LeetCode."
+sidebar_position: 11
+---
+
+## Problem Description
+
+Given a string `s`, return the number of palindromic substrings in it.A string is a palindrome when it reads the same backward as forward.
+
+A substring is a contiguous sequence of characters within the string.
+
+### Examples
+
+**Example 1:**
+
+```
+Input: s = "abc"
+Output: 3
+Explanation: Three palindromic strings: "a", "b", "c".
+```
+
+**Example 2:**
+
+```
+Input: s = "aaa"
+Output: 6
+Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
+```
+
+### Constraints
+
+- `1 <= s.length <= 1000`
+- `s` consists of lowercase English letters.
+
+---
+
+## Solution for Count Palindromic Substrings Problem
+
+To solve this problem, we need to count all the palindromic substrings in the given string `s`.
+
+### Approach: Expand Around Center
+
+The idea is to consider each possible center of a palindrome and expand outwards as long as we have a valid palindrome. For each center, count the palindromic substrings.
+
+#### Steps:
+
+1. **Identify Centers:**
+ - There are 2*n - 1 centers for palindromes in a string of length `n` (including the space between characters for even-length palindromes).
+
+2. **Expand Around Center:**
+ - For each center, expand outwards to check if the substring is a palindrome. If it is, increment the count.
+
+### Brute Force Approach
+
+The brute force approach involves checking all substrings and verifying if each substring is a palindrome. This is inefficient and has a time complexity of $O(n^3)$.
+
+### Optimized Approach
+
+The optimized approach, using the Expand Around Center method, has a time complexity of $O(n^2)$.
+
+### Code in Different Languages
+
+