The Beauty of Previous Knowledge - More Leetcode Problems #Day2

Removing an element in an array (I4G 10 Days Of Code Challenge)

One of the most beautiful things in the world is when a current problem being faced has certain similarities with a problem that has already been faced. This was the case for this current problem as it shared a lot of similarity with Day 1's Challenge.

The Challenge

2_question.png

Approach to Solution

As you can see, this challenge shares similar attributes to the first challenge, so basically using a similar idea of Day 1's challenge, I arranged my code with this process

  1. Loop through each of the array's elements
  2. Check if each element corresponds with the value given
  3. If value corresponds, delete the value in array
  4. Increment the counter of the array A pseudocode would look like this:
while count is less than array length
  if value is in array
    delete array[index]
  increment count

k = length of array

2_accepted.png

2_results.png

2_results_2.png

Finally Did It