🔥BEGINNER FRIENDLY👏 C++ CODE  || O(n) 💯 || EASY EXPLANATION 😊👍
Intuition & Approach :\n\nLets see how you can solve this problem:\n\n1. Frequency Map Construction:\n   - You create an unordered map mp to store the frequency
# Intuition & Approach :\n\nLets see how you can solve this problem:\n\n1. **Frequency Map Construction**:\n   - You create an unordered map `mp` to store the frequency of each element in the input vector `nums`.\n   - For each element in `nums`, you increment its count in the map (`mp[i]++`).\n   - This allows you to quickly check if a value from the linked list exists in `nums`.\n\n2. **Pointer Initialization**:\n   - You use two pointers, `curr` and `prev`, both initially set to the `head` of the linked list:\n     - `curr` is used to traverse the list.\n     - `prev` is used to keep track of the previous node, which is necessary for node deletion.\n\n3. **Traversal and Removal**:\n   - You iterate through the linked list using the `curr` pointer until it becomes `nullptr` (reaching the end of the list).\n   - For each node, you check if its value exists in the `mp` map (i.e., `mp[curr->val] != 0`).\n     - **If the node\u2019s value exists in the map (i.e., should be removed)**:\n       - If `prev == curr` (this occurs when the node to be removed is at the head of the list):\n         - You move the `head` to the next node (`head = head->next`), effectively removing the current node from the list.\n         - Move `curr` to the next node (`curr = curr->next`) and update `prev` to point to `curr` as well.\n       - If `prev != curr` (i.e., the node to be removed is somewhere after the head):\n         - You skip the current node by making `prev->next = curr->next`, bypassing the node to be removed.\n         - Move `curr` to the next node (`curr = curr->next`), but `prev` remains pointing to the previous node (since it already bypassed the current node).\n     - **If the node\u2019s value does not exist in the map (i.e., should be retained)**:\n       - You simply move both `prev` and `curr` pointers to the next nodes in the list (`prev = curr; curr = curr->next`).\n\n4. **Return the Updated List**:\n   - After traversing and modifying the list, the function returns the `head` pointer, which now points to the modified list with the unwanted nodes removed.\n\n\n\n\n# Complexity\n- **Time complexity** :  **O(n + m)** , where **n**-> *size of nums*, **m**-> *number of nodes* in the linked list.\n\n- **Space complexity** : **O(n)**, where **n**-> elements from nums in the unordered map.\n\n# Code\n```cpp []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* head) {\n        unordered_map<int,int>mp;\n        for(auto i:nums)    mp[i]++;\n        ListNode* curr=head;\n        ListNode* prev=head;\n\n        while(curr!=nullptr){\n            if(mp[curr->val]>0){\n\n                if(prev==curr){\n                    if(head==curr) head=head->next;\n\n                    curr=curr->next;\n                    prev=curr;\n                }else {\n                    curr=curr->next;\n                    prev->next=curr;\n                }\n            }\n            else {\n                prev=curr;\n                curr=curr->next;\n\n            }\n        }\n\n        return head;\n        \n    }\n};\n```
['Ordered Map', 'C++']