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 we iterate through the string once to filter out non-alphanumeric characters and convert them to lowercase, which takes O(n) time. The comparison of the list `s` with its reverse `s[::-1]` also takes O(n) time, leading to an overall time complexity of O(n). The space complexity is also O(n) because we create a new list `s` that stores the filtered and lowercased characters. In the worst case, if all characters in the input string are alphanumeric, the space used by the list will be proportional to the length of the input string. Thus, the space complexity is O(n).
Simply convert the input to lower if it’s an alphanumeric char then just return if it’s equal to it’s reversed string