Posts

Showing posts from July, 2022

Longest Palindromic Substring in javascript

 Hello friends,   If you come here to check the solution of the following question.  Longest Palindromic Substring in javascript this question is asked in LeetCode as a Longest Palindromic Substring (Question Number -5) and its difficulty is medium. So let's first understand the question. Given a string  s , return  the longest palindromic substring  in  s . Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb"   Constraints: 1 <= s.length <= 1000 s  consist of only digits and English letters. So the solution to the above question is. /** * @param {string} s * @return {boolean} */ var longestPalindrome = function(s) { let startIndex = 0; let maxLength = 1; function expandMiddle(left, right) { while (left >= 0 && right < s.length && s[left] === s[right]) { const currentPalindromeLength = ri...

JavaScript find valid palindrome or not | leet code question 125

Hello friends,   If you come here to check the solution of the following question.   JavaScript find valid palindrome or not this question is asked in LeetCode as a valid palindrome(Question Number -125) and its difficulty is easy. If you search on google mostly we get solutions in Java, Python, or C++. if we are lucky then only we get the solution in javascript for the leet code questions. So let's first understand the question. A phrase is a  palindrome  if it reads the same forward and backward after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters. Alphanumeric characters include letters and numbers. Given a string  s , return  true  if it is a  palindrome , or  false  otherwise . Example 1: Input: s = "A man, a ...