Approach
Simply convert the input to lower if it’s an alphanumeric char then just return if it’s equal to it’s reversed string
Search
Jun 27, 20241 min readThe time complexity of the provided solution is O(n), where n is the length of the input string `s`. This is because the algorithm iterates through the string once to filter out non-alphanumeric characters and convert them to lowercase, which takes linear time. The comparison of the list `s` with its reverse `s[::-1]` also takes O(n) time, resulting in an overall time complexity of O(n). The space complexity is also O(n) due to the creation of a new list that stores the filtered and lowercased characters. In the worst case, if all characters in the input string are alphanumeric, the space used for this list will be proportional to the length of the input string. Thus, the space complexity is O(n) as well.
Simply convert the input to lower if it’s an alphanumeric char then just return if it’s equal to it’s reversed string