All problems
1127MediumArrayHash TableLinked List

Dropping the Banned Tags From the Chain

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3217Delete Nodes From Linked List Present in Array

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A run of codes banned is given, no two of them the same, and a chain of tags follows.

Because the harness passes plain JSON, the chain reaches you as chain, listing the tag codes in order from the front.

Drop every tag whose code turns up in banned and return what is left, again as a plain list read from the front. At least one tag always survives.

Examples

Example 1

Input
banned = [1, 3, 5], chain = [1, 2, 3, 4, 5, 6]
Output
[2, 4, 6]

The three odd codes are banned, so the three even tags survive in the order they stood.

Example 2

Input
banned = [7], chain = [7, 1, 7, 2, 7, 3]
Output
[1, 2, 3]

Every tag coded 7 goes, whichever position it held, and the others keep their order.

Example 3

Input
banned = [6], chain = [1, 2, 3, 4, 5]
Output
[1, 2, 3, 4, 5]

No tag carries the banned code, so the chain comes back untouched.

Constraints

  • 1 <= banned.length <= 10^5
  • 1 <= banned[i] <= 10^5
  • no two codes in banned are the same
  • 1 <= chain.length <= 10^5
  • 1 <= chain[i] <= 10^5
  • at least one tag carries a code missing from banned

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def modified_list(banned: list[int], chain: list[int]) -> list[int]:
Java
public int[] modifiedList(int[] banned, int[] chain)
September 7
Apply