DEV Community

Cover image for #10daysofcodechallenge by Ingressive for Good (#Day 3)
Dennar David
Dennar David

Posted on

#10daysofcodechallenge by Ingressive for Good (#Day 3)

I've just begun a 10-day coding challenge organized by Ingressive for Good and I'll be sharing my thoughts on Day 3 of the challenge.

Let me briefly describe how the challenge works before I share my experience with you. From September 21 through October 30, 2022, the challenge is to solve one common algorithm problem every day for ten days.

Today's algorithm problem was "The problem states that we need to determine if a given integer is a palindrome." It is the 9th algorithm challenge on "Leetcode.com".

How do you define a palindrome? An Oxford dictionary definition of a palindrome is a word, phrase, or sequence that reads the same both forward and backward.

I'll now discuss my algorithm solving experience. There are numerous techniques to determine whether a word, phrase, or sequence is a palindrome, but the crucial question is how to determine this using codes.

I had to apply the two pointer algorithm to address the problem I was presented with. I initialized two position pointers, one at the beginning of the string and the other at the end, after first converting the number to a string. After then, a while loop was utilized to iterate through each element of the string while comparing and, as necessary, increasing and reducing the pointers. The sequence is not a palindrome if the values at any of the position pointers are not equal.

This task was completed in javaScript, took 162 milliseconds to execute, and consumed about 50 MB of memory.

Top comments (0)