Problem
Ask
Submissions
Solution

Solution: Palindrome Permutation

Statement

Naive approach

The naive solution is to first compute all possible permutations of a given string and then iterate over each permutation to see if it’s a palindrome. We can use two pointers to traverse the computed permutation from the beginning and the end simultaneously, comparing each character at every step. If the two pointers point to the same character until they cross each other, the string is a palindrome.

The number of possible permutations for a string of length nn is n!n!, and it requires iterating through the nn characters to construct each permutation. Therefore, it will take O(n!×n)O(n! \times n) ...

Problem
Ask
Submissions
Solution

Solution: Palindrome Permutation

Statement

Naive approach

The naive solution is to first compute all possible permutations of a given string and then iterate over each permutation to see if it’s a palindrome. We can use two pointers to traverse the computed permutation from the beginning and the end simultaneously, comparing each character at every step. If the two pointers point to the same character until they cross each other, the string is a palindrome.

The number of possible permutations for a string of length nn is n!n!, and it requires iterating through the nn characters to construct each permutation. Therefore, it will take O(n!×n)O(n! \times n) ...