How to check whether a given sentence is a palindrome

Rakesh Narang
2 min readMay 18, 2020

--

Introduction

Let’s solve the following leetcode problem: -

We want to check whether a given sentence is a palindrome.

Step 1: Let’s read the valid palindrome problem statement on leetcode

Step 2: Let’s break down how we will write the isPalindrome method by converting our algorithms to functions

Step 3: We will first remove all non qualifying characters from String

Step 4: After the string is cleaned up, let’s just check whether it is a simple palindrome using the two-pointer technique

Step 5: Submit and see how the solution fares! Mine is roughly 40% better than all solutions, which means there is a better approach that I can code

Final Words

If you like this story, follow me on insta: https://www.instagram.com/stories/global.software.developers/?hl=en

If you like this story, follow me on insta: https://www.instagram.com/stories/global.software.developers/?hl=en

--

--

Rakesh Narang
Rakesh Narang

No responses yet