I completed arrays yesterday so Today let’s solve a string question

Q3. Valid Palindrome

Question link: https://leetcode.com/problems/valid-palindrome/description/

Thought Process

Extract the words. Reverse the words list with space character in between and finally return the list version of the string

Pseudocode and Test case

TASKs

  1. Convert into string
  2. extract the words by using empy_space as the marking
  3. reverse the words list
  4. join with spaces
  5. return the List version

Python CODE

def isPalindrome(s):
    str = ''.join(e.lower() for e in s if e.isalnum() )
    return str == str[::-1]

Complexity analysis

Why?

TC: O(n)

SC: O(n)