Algorithm Practice

Sean Ransonette
2 min readAug 1, 2021

I recently had a mock technical interview an I really had issues solving the algorithm that was presented to me. I already knew going into the interview I would have trouble because I have honestly not put enough time into practicing algorithms. I asked my Flatiron cohort friend Jake if he would be interested. He agreed and we decide to go to LeetCode.com and practice some easy level difficulty problems

So far I have solved two problems. Two Sum and Palindrome Number. It is still extremely tough for me to handle and have to Google a ton of ideas for how to solve the problems. Palindrome Number specifically was very interesting. Jake was solving it in Ruby and I was solving it in JavaScript.

Above is the problem from Leet code. First thing I needed to do was allow myself the ability to iterate through the numbers of the variable X by using the following

let array = x.toString().split(‘’)

Once I figured that out I had a bit of trouble. Initially I wanted to iterate through the new variable array twice at the same time. I attempted this with a nested iteration. It did not work though. The first iteration would hit the first number and then the nested iteration would run to completion. Mixing all the numbers to compare.

After lot of Google and a bit of help from Jake I realized I did not need to iterate twice but only once and then compare the end of the array variable to the beginning and slowly move inward. I did that by doing the following.

These are the final run time results for my solution.

This is only the beginning of my algorithm practice and I look forward to becoming even better at JavaScript.

--

--