🚀 Day 83 of #100DaysOfCode Solved 3217. Delete Nodes from Linked List Present in Array on LeetCode 🔗 🧠 Key Insight: We need to remove all nodes from the linked list whose values exist in a given array 👉 Fast lookup is required → use a HashSet ⚙️ Approach (HashSet + Traversal): 1️⃣ Store all array elements in a HashSet 🔹 set.add(nums[i]) 2️⃣ Use a dummy node before head 🔹 Helps handle deletion at head easily 3️⃣ Traverse the list: 🔹 If node.next.val exists in set → delete it 👉 node.next = node.next.next 🔹 Else → move forward 4️⃣ Return dummy.next ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(m) #100DaysOfCode #LeetCode #DSA #LinkedList #HashSet #TwoPointers #Java #InterviewPrep #CodingJourney
Delete Nodes from Linked List Present in Array on LeetCode
More Relevant Posts
-
Day 71 - Delete Middle Node Handling linked list traversal to identify and remove the middle node efficiently. Approach: • Traverse once to count nodes • Find middle index using n/2 • Traverse again to reach previous node • Update pointers to remove middle Key Insight: Careful handling needed when list size is small (edge cases) Time Complexity: O(n) Space Complexity: O(1) #Day71 #LeetCode #Java #CodingPractice #TechJourney #DSA #LinkedList
To view or add a comment, sign in
-
-
Day 87/100 🚀 | #100DaysOfDSA Solved LeetCode 345 – Reverse Vowels of a String today. Approach: Used two pointers + HashSet for fast vowel lookup. • Converted string to a char array (for in-place modification) • Maintained a HashSet of vowels (both lowercase & uppercase) • Used two pointers (left, right) Moved left forward until it finds a vowel Moved right backward until it finds a vowel • Swapped both vowels and continued Finally converted the array back to string. Time Complexity: O(n) Space Complexity: O(1) (ignoring set size as constant) Key takeaway: When checking membership frequently (like vowels), using a HashSet gives O(1) lookup, making two-pointer solutions efficient. #100DaysOfDSA #LeetCode #DSA #Java #TwoPointers #Strings #HashSet #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
✅ LeetCode Top Interview 150 – Day 91 Today I solved Clone Graph Key Idea : Use DFS/BFS traversal to clone each node Maintain a HashMap to store original → cloned node mapping For each node, create a copy and recursively clone its neighbors Reuse already cloned nodes from map to avoid duplication and cycles This approach ensures a correct deep copy of the graph #DSA #Java #Leetcode #Day91
To view or add a comment, sign in
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
Linked list problems often become simpler when you break them into clear steps. 🚀 Day 111/365 — DSA Challenge Solved: Remove Nth Node From End of List Problem idea: We need to remove the nth node from the end of a linked list. Efficient approach: Convert the problem into finding the (size − n)th node from the start. Steps: 1. Traverse the list to calculate its size 2. If n equals size → remove the head 3. Otherwise, find the node just before the target 4. Update pointers to remove the node This simplifies the problem using basic traversal and pointer manipulation. ⏱ Time: O(n) 📦 Space: O(1) Day 111/365 complete. 💻 254 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #LinkedList #LeetCode #LearningInPublic
To view or add a comment, sign in
-
-
Day 63 - Odd Even Linked List Today’s problem was about rearranging nodes based on their positions. Approach: • Maintain two pointers → odd and even • Traverse and rearrange links in-place • Keep track of even head to attach later • Merge odd list with even list at the end Key insight: 👉 Focus on node positions, not node values. Time Complexity: O(n) Space Complexity: O(1) #Day63 #LeetCode #Java #LinkedList #CodingPractice #TechJourney #DSA
To view or add a comment, sign in
-
-
Day 73 - Merge K Sorted Lists Understanding how to merge multiple sorted lists using an optimized approach. Approach: • Use a priority queue (min-heap) • Add the head of each list • Extract the smallest node • Add its next node back to heap • Repeat until heap is empty Key Insight: Heap helps always pick the smallest element among k lists efficiently Time Complexity: O(N log k) Space Complexity: O(k) #Day73 #LeetCode #Java #CodingPractice #TechJourney #DSA #LinkedList
To view or add a comment, sign in
-
-
Some of the hardest problems become manageable once you recognize a repeating pattern. 🚀 Day 105/365 — DSA Challenge Solved: Subarrays with K Different Integers Problem idea: We need to count subarrays that contain exactly k distinct integers. Efficient approach: Use the powerful trick: subarrays with exactly k distinct = subarrays with ≤ k distinct − subarrays with ≤ (k − 1) distinct Steps: 1. Use a sliding window with a hashmap to track frequency of elements 2. Expand window by moving right pointer 3. If distinct count exceeds k, shrink window from the left 4. Count valid subarrays ending at each index 5. Subtract results to get exact count This pattern converts a hard problem into a manageable one. ⏱ Time: O(n) 📦 Space: O(n) Day 105/365 complete. 💻 260 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #SlidingWindow #HashMap #LeetCode #LearningInPublic
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟔𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on rotating an array to the right by k steps efficiently. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Rotate Array 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐑𝐞𝐯𝐞𝐫𝐬𝐚𝐥 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞 • First normalized k using k % n • Reversed the entire array • Reversed the first k elements • Reversed the remaining elements This results in the desired rotation. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Reversal technique is a powerful in-place trick • Breaking a problem into steps simplifies logic • Modulo helps handle large values of k • In-place operations reduce space complexity 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sometimes the best solution is not shifting elements — but rearranging them smartly. 63 days consistent 🚀 On to Day 64. #DSA #Arrays #TwoPointers #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
🎉🎉 Day-32 of #60DaysOfDSA 🎉🎉 Problem: K-th Element of Two Sorted Arrays 👉 Problem Statement: Given two sorted arrays, find the element that would appear at the k-th position in the merged sorted array. 👉 Approach Used (Two Pointer / Merge Logic): ✔️ Use two pointers i and j for both arrays ✔️ Traverse like merge step of merge sort ✔️ Keep counting elements until count == k ✔️ Return the k-th element 👉 Time Complexity : O(n + m) #dsa #problemsolving #java #geekstreak60
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development