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
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.