from typing import List


class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        counter = 0
        nums_iterator_index = len(nums) - 1
        while nums_iterator_index >= 0:
            if nums[nums_iterator_index] == val:
                del nums[nums_iterator_index]
            else:
                counter += 1
            nums_iterator_index -= 1
        return counter


print(Solution().removeElement(nums=[3, 2, 2, 3], val=3))
print(Solution().removeElement(nums=[0, 1, 2, 2, 3, 0, 4, 2], val=2))
