Delete Nodes From Linked List Present in Array
Real-world version: Dropping the Banned Tags From the ChainThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def modified_list(banned: list[int], chain: list[int]) -> list[int]:public int[] modifiedList(int[] banned, int[] chain)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Minimum Pair Removal to Sort Array IReal-world version: Merging the Smallest Neighbouring Pair Until the Strip RisesEasy
- Two SumReal-world version: Ledger ReconciliationEasy
- Next Greater Element IReal-world version: Auction Watchlist HighsEasy
- Contains Duplicate IIReal-world version: Nearby Repeat TrimEasy