#K44392. Remove Element from Array
Remove Element from Array
Remove Element from Array
You are given an array of (n) integers and an integer (val). Your task is to remove all occurrences of (val) from the array in-place, maintaining the relative order of the remaining elements. After removal, let (k) be the new length of the array; the first (k) elements should be the elements from the original array that are not equal to (val). The elements beyond the first (k) positions can be ignored.
For example, given the array [3, 2, 2, 3] and (val = 3), the new length is 2 and the modified array is [2, 2].
inputFormat
The input is given via standard input (stdin) in the following format:
The first line contains an integer (n), the number of elements in the array. The second line contains (n) space-separated integers representing the array elements. The third line contains a single integer (val) that needs to be removed from the array.
outputFormat
Output to standard output (stdout) in the following format:
The first line should contain the new length (k) of the array after removing all occurrences of (val). The second line should contain (k) space-separated integers which are the first (k) elements of the updated array.## sample
4
3 2 2 3
3
2
2 2
</p>