Remove All Matching Values

L3 Easy Two Pointers
Concept
When you must remove values in place, use a write pointer for the "keep" position and a read pointer that scans the whole array.
Given an array nums and an integer val, remove every occurrence of val in place and return the number of remaining elements. The first count slots of nums should hold those remaining elements in their original relative order; ignore the rest.
Examples
▸ nums = [3, 2, 2, 3], val = 3
→ 2
▸ nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2
→ 5
▸ nums = [], val = 5
→ 0
Progressive Hints
Hint 1 · Nudge
Same write-pointer idea as the zeroes problem, but the value to skip is val.
Hint 2 · Plan
Keep a write pointer starting at 0. Loop over nums; whenever a value is not val, place it at the write pointer and advance the pointer. Return the write pointer as the count of kept elements.
Hint 3 · Approach
write = 0. For each n in nums: if n != val, set nums[write] = n and write = write + 1. Return write.
Output
// Run your code to see the output here.