Valid Palindrome

Valid palindrome.

Given an input string. We have to write a code to check if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For this problem, consider the empty string as a valid palindrome.

For Example –

Example 1:

Input: “A man, a plan, a canal: Panama”
Output: true

Explanation: After removing non-alphanumeric characters, the string is amanaplanacanalpanama. So, it’s a palindrome

Example 2:

Input: “race a car”
Output: false

Reverse Words in a String

How to reverse words in a String?

In this problem, we have given an input string, we have to write a code to reverse the string word by word.

Example 1:

Input : “the carpet is green”

Output: “green is carpet the”

Example 2:

Input : ”  Java Ebook  “

Output: “Ebook Java”

Explanation: The reversed string should not contain leading or trailing spaces.

Example 3:

Input : “a good   example”

Output: “example good a”

Explanation: We have reduce multiple spaces between two words to a single space in the reversed string.

Note:

  • The Input string may contain leading or trailing spaces. However, the reversed string should not contain leading or trailing spaces.
  • We have to reduce multiple spaces between two words to a single space in the reversed string.

Backspace String Compare

Let’s discuss an interesting problem Backspace String Compare.

Given two strings S and T containing backspaces. We have to write a code to check if they are equal.  In string, # means a backspace character.

Example 1:

Input: S = “ab#c”, T = “ad#c”

Output: true

Explanation: Both S and T become “ac”.

Example 2:

Input: S = “ab##”, T = “c#d#”

Output: true

Explanation: Both S and T become “”.

Example 3:

Input: S = “a##c”, T = “#a#c”

Output: true

Explanation: Both S and T become “c”.

Example 4:

Input: S = “a#c”, T = “b”

Output: false

Explanation: S becomes “c” while T becomes “b”.