#K73527. Remove Occurrences
Remove Occurrences
Remove Occurrences
Given a list of integers and an integer value, remove all occurrences of the integer from the list and output the new length of the list.
The problem can be formulated as: $$ remove_occurrences(nums, val) = |{ x \in nums : x \neq val }| $$ where $$|\cdot|$$ denotes the length of the list. Ensure that the relative order of the remaining elements is preserved.
inputFormat
The input consists of three parts:
1. The first line contains an integer (n) representing the number of elements in the list.
2. The second line contains (n) space-separated integers.
3. The third line contains an integer (val) that is to be removed from the list.
outputFormat
Output a single integer representing the new length of the list after all occurrences of (val) have been removed.## sample
7
1 2 3 4 3 2 1
3
5