Kotlin | O(max(n, nodes)) time, O(maxNum) space | count + iterator  (974ms)
Intuition\n\n- nums[i] from 1 to 10^5 - we can reduce the complexity of evaluation "should we remove this number" downto O(1)\n- just keep head and last pointer
# Intuition\n\n- `nums[i]` from 1 to 10^5 - we can reduce the complexity of evaluation "should we remove this number" downto O(1)\n- just keep `head` and `last` pointers for a new list, and carefully iterate throught original building answer\n\n# Complexity\n- Time complexity: $$O(n)$$ to iterate through `nums`, then throught list. Checking "should remove?" is O(1)\n\n- Space complexity: $$O(maxNum)$$ to keep array for O(1) checking\n\n# Code\n```kotlin []\nclass Solution {\n\n    fun modifiedList(nums: IntArray, head: ListNode): ListNode {\n        val shouldRemove = BooleanArray(MAX_NUM+1)\n        for (num in nums) shouldRemove[num] = true\n\n        var first: ListNode? = null\n        var last: ListNode? = null\n\n        var current: ListNode? = head\n        while (current != null) {\n            if (!shouldRemove[current.`val`]) {\n                val newNode = ListNode(current.`val`)\n                if (first == null) {\n                    first = newNode\n                    last = first\n                } else {\n                    (last ?: error("last is null")).next = newNode\n                    last = last.next\n                }\n            }\n            current = current.next\n        }\n\n        return first ?: error("All items were removed")\n    }\n\n\n    companion object {\n        private const val MAX_NUM = 100_000  // 10^5\n    }\n\n}\n\n```
['Kotlin']