DEV Community

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

Posted on • Updated on

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

I've just begun a 10-day coding challenge organized by Ingressive for Good and I'll be sharing my thoughts on Day 1 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 "Removing duplicates from a sorted list". It is the 26th algorithm challenge on "Leetcode.com"

I'll now share my experience. This was a little difficult for me because I had never really dealt with algorithm issues before. To do this, I had to understand the two pointer algorithm's basic principles. I created a solution utilizing nested for loops, which worked on my local system but was rejected by Leetcode since it did not adhere to their specifications.

For my final solution, I created a variable to act as a position pointer and a for loop to iterate through the array. At each position of the pointer, the loop is run to compare the value at that position and the pointers position; if they are the same, the values at the two positions are swapped, and the pointer is incremented. The last sorted array, where "n" is the "final pointer value," is returned if its first "n" elements are unique.

I utilized javaScript to solve the issue, which had a runtime of 88 milliseconds and consumed roughly 44.4 MB of memory.

Top comments (0)