Posted by : Abdallah Rabie

Problem Name:  Remove Element 

Platform: leetcode



This problem is so close to the previous Remove Duplicates From Sorted Array 
This problem have 2 solution one wasting memory but pretty easy and the other is small code but much headache lets start.
The problem want to remove a specific element  given by the user in every place in the array and return the size of the new array.
The function given by the platform have 3 parameter:
  1. the given array 
  2. the size of the array
  3. the value need to be removed



First algorithm:
  • Create new array and a new variable with initial value 0 to store the new size.
  • Check every element in the given array if the element not equal to value given by the user store it in the new array and increment the 
  • return  the variable 


Second algorithm:

  • this algorithm is to close to the Remove Duplicates From Sorted Array  Algorithm 
  • Create a for loop to go though the whole array and create a new variable with initial value 0 to store the new size.
  • Check if the element not equal to the value store this value in the array with index variable you created in the first step and increment the the variable with 1.
  • Return the new size array.




and finally 






Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © 2025 Quarks - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -