#C13476. Remove Occurrences

    ID: 43018 Type: Default 1000ms 256MiB

Remove Occurrences

Remove Occurrences

You are given a list of integers and an integer x. Your task is to remove all occurrences of x from the list and print the resulting list. If all elements are removed, print an empty line.

Input Format: The first line contains zero or more space‐separated integers representing the list. The second line contains a single integer x which is the value to remove from the list.

Output Format: Print the filtered list as space-separated integers on one line. If the resulting list is empty, print nothing.

Examples:

  • Input: 1 2 3 4 2 5 and 2 → Output: 1 3 4 5
  • Input: 1 2 3 4 5 and 6 → Output: 1 2 3 4 5
  • Input: 2 2 2 2 2 and 2 → Output: (an empty line)

The problem is simple and can be solved using list comprehensions or filtering methods. The time complexity is \(O(n)\) where \(n\) is the number of elements in the list.

inputFormat

The input consists of two lines:

  • The first line contains zero or more space-separated integers (this represents the list). The line can be empty, indicating an empty list.
  • The second line contains a single integer x, the number to be removed.

outputFormat

Output a single line containing the list after removing all occurrences of x. The integers should be space-separated. If the list is empty, output an empty line.

## sample
1 2 3 4 2 5
2
1 3 4 5