Remove Fibonacci Values from a Linked List
Problem Given a number N and a singly linked list of length L (which may contain duplicates), compute the first N terms of the Fibonacci series; then, for any value appearing in that series, remove every occurrence of it from the linked list.
Input / Output
- Input: integer N, and head of a singly linked list.
- Output: the head of the modified list with all Fibonacci-valued nodes removed.
Constraints
- The list may contain duplicate values — all copies must go, not just the first.
- N and L are independent sizes.
- Fibonacci values grow exponentially, so for large N the terms quickly exceed any plausible node value; guard against overflow if N is unbounded.
Example
- N = 5 -> Fibonacci terms [0, 1, 1, 2, 3]. Given the list 4 -> 2 -> 7 -> 2 -> 3 -> 9, the result is 4 -> 7 -> 9: both 2 nodes and the 3 node are removed.
- Tricky cases: removal at the head (2 -> 4 becomes 4) — which is why a dummy head helps; and a list where every node is a Fibonacci value, leaving an empty list.
asked …