A quick guide to the infamous palindrome question

Woodelin florveus
2 min readJun 3, 2021

--

During my journey of trying to learn javascript algorithms and data structures. I stumbled upon the infamous and popular Palindrome question, which took me a few hours to solve. Looking at this question I did not know where to start. A few minutes into the problem I noticed that I can iterate through the string, however under what condition will it return true or false and how can I check? Since it was my first time tackling this problem I decided to first approach the problem with pseudocode and solve it with brute force.

My pseudocode approach was this.

My goal was to iterate through the string, however, I had to turn the string into an array, therefore, using the split method. This method makes it easier to iterate through the string. Now that I’m able to go through every word, it’s time to implement the proper condition. This particular part of the pseudo-code had me stuck. With a bit of research and google, I figured out what the if statement needed to check for true or false. I had to check if the word from left to right is equal to the same in reverse. To check if the word in reverse takes the length of the array subtracted by the index and subtract 1 for example

array [array. length — i — 1]. If the condition is true it will return true, otherwise false.

Now it is time to make the pseudo-code come to life. Now that our thought process is clear we can now solve the problem. Here is the final solution.

--

--

No responses yet