💼 Day 54 of #100DaysOfCode Challenge 🚀 📘 Problem: LeetCode #217 – Contains Duplicate 🧠 Topic: HashSet | Array | Data Structures 🔍 Problem Statement: Given an integer array nums, return true if any value appears at least twice in the array, and false if every element is distinct. ⚙ Approach: Used a HashSet to check for duplicates efficiently. Traverse through each number in the array. If the number already exists in the set → return true. Otherwise, add it to the set and continue. If loop ends with no duplicates → return false. 💻 Java Solution: import java.util.HashSet; public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int num : nums) { if (set.contains(num)) { return true; } set.add(num); } return false; } } ⏱ Complexity Analysis: Time: O(n) Space: O(n) 💬 Takeaway: Simple but powerful — using the right data structure like HashSet can make problems easy and efficient to solve. ⚡ #100DaysOfCode #Day54 #LeetCode #Java #CodingChallenge #DSA #HashSet #ProblemSolving #Programmer #TechJourney
Solved LeetCode #217 with HashSet in Java
More Relevant Posts
-
💼 Day 54 of #100DaysOfCode Challenge 🚀 📘 Problem: LeetCode #217 – Contains Duplicate 🧠 Topic: HashSet | Array | Data Structures 🔍 Problem Statement: Given an integer array nums, return true if any value appears at least twice in the array, and false if every element is distinct. ⚙ Approach: Used a HashSet to check for duplicates efficiently. Traverse through each number in the array. If the number already exists in the set → return true. Otherwise, add it to the set and continue. If loop ends with no duplicates → return false. 💻 Java Solution: import java.util.HashSet; public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int num : nums) { if (set.contains(num)) { return true; } set.add(num); } return false; } } ⏱ Complexity Analysis: Time: O(n) Space: O(n) 💬 Takeaway: Simple but powerful — using the right data structure like HashSet can make problems easy and efficient to solve. ⚡ #100DaysOfCode #Day54 #LeetCode #Java #CodingChallenge #DSA #HashSet #ProblemSolving #Programmer #TechJourney
To view or add a comment, sign in
-
-
💼 Day 54 of #100DaysOfCode Challenge 🚀 📘 Problem: LeetCode #217 – Contains Duplicate 🧠 Topic: HashSet | Array | Data Structures 🔍 Problem Statement: Given an integer array nums, return true if any value appears at least twice in the array, and false if every element is distinct. ⚙️ Approach: Used a HashSet to check for duplicates efficiently. Traverse through each number in the array. If the number already exists in the set → return true. Otherwise, add it to the set and continue. If loop ends with no duplicates → return false. 💻 Java Solution: import java.util.HashSet; public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int num : nums) { if (set.contains(num)) { return true; } set.add(num); } return false; } } ⏱ Complexity Analysis: Time: O(n) Space: O(n) 💬 Takeaway: Simple but powerful — using the right data structure like HashSet can make problems easy and efficient to solve. ⚡ #100DaysOfCode #Day54 #LeetCode #Java #CodingChallenge #DSA #HashSet #ProblemSolving #Programmer #TechJourney
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙️ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
To view or add a comment, sign in
-
-
𝗕𝗲𝗵𝗶𝗻𝗱 𝘁𝗵𝗲 𝗦𝗰𝗲𝗻𝗲𝘀 𝗼𝗳 𝗝𝗮𝘃𝗮 𝗔𝗿𝗿𝗮𝘆𝗟𝗶𝘀𝘁! Today, I implemented a 𝗗𝘆𝗻𝗮𝗺𝗶𝗰 𝗔𝗿𝗿𝗮𝘆 in Java — building the logic from scratch to understand how ArrayList actually works under the hood. ⚙️ This exercise gave me hands-on exposure to how resizing, shifting, and accessing elements are efficiently handled in dynamic data structures. 𝗛𝗲𝗿𝗲’𝘀 𝘄𝗵𝗮𝘁 𝗜 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗲𝗱 👇 🔹 add(element) — to append new items dynamically 🔹 add(index, element) — to insert at a specific position 🔹 get(index) — to fetch values efficiently 🔹 set(index, element) — to replace existing elements 🔹 remove(index/element) — to delete items and shift elements 🔹 contains(element) — to check for existence 🔹 isEmpty() & clear() — to manage and reset the structure 𝗜𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝗱𝗲 : https://lnkd.in/gXEfwXvf 📘 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Recreating ArrayList from scratch deepened my understanding of how memory reallocation, indexing, and dynamic resizing make it one of the most powerful data structures in Java’s Collection Framework. Learning the “how” behind the “what” truly builds stronger foundations. 💪 #Java #DataStructures #ArrayList #CodingJourney #LearningByDoing #SoftwareEngineering #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Today’s challenge was all about implementing an LRU (Least Recently Used) Cache in Java — a problem that truly tests your understanding of data structures and memory optimization. 💡 🧩 Problem Statement: Design a data structure that supports: get(key) → Returns value if key exists, else -1 put(key, value) → Inserts or updates value Both should work in O(1) time complexity. It should automatically remove the least recently used entry when the cache exceeds its capacity. ⚙️ What I Implemented: ✅ Used LinkedHashMap with access order enabled. ✅ Overrode removeEldestEntry() to maintain fixed capacity. ✅ Ensured get() and put() operations are constant time. ✅ Tested the cache with sample inputs to confirm LRU behavior. 📘 Sample Output: When I executed the program, I got: {3=30, 1=10, 4=40} This confirmed that the oldest (least recently used) entry was correctly removed when the cache was full. 🧠 Concepts Strengthened: Understanding LinkedHashMap internals Efficient memory management O(1) data retrieval and replacement logic Practical use of overriding and encapsulation 🔥 Each day of this challenge pushes me closer to mastering clean, efficient, and optimized Java code. This one made me appreciate how real-world caching systems like browsers and databases manage performance. 💬 Next Goal: To explore advanced multithreading problems and optimize concurrent data structures. ✨ Almost at the finish line — Day 96/100! Every line of code is another step toward growth. 💪 #100DaysOfCode #Java #DataStructures #CodingChallenge #ProblemSolving #LinkedHashMap #SoftwareEngineering #LearningJourney #DeveloperCommunity
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
To view or add a comment, sign in
-
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode – LeetCode #206: Reverse Linked List Today’s challenge was one of the most classic problems in data structures — reversing a linked list. This problem is a great way to strengthen your understanding of pointers and linked list manipulation. 🧩 Problem: Given the head of a singly linked list, reverse it and return the new head. ⚙ Approach: I used an iterative approach with three pointers: prev, curr, and next. Store the next node Reverse the current node’s pointer Move forward until the list is reversed 🧠 Key Learning: This problem really helped me visualize how pointers work in linked structures — a great exercise for understanding memory links and iterative logic. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Here’s my simple Java solution: class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null, curr = head; while (curr != null) { ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } return prev; } } 🔥 Every day, one step closer to mastering data structures! #Day53 #LeetCode #Java #100DaysOfCode #CodingJourney #LinkedList #DSA #Programming #ReverseLinkedList
To view or add a comment, sign in
-
-
🚀 Just Solved LeetCode #1367 — Linked List in Binary Tree 📘 Problem: Given the head of a linked list and the root of a binary tree, determine whether all the elements of the linked list appear as a downward path in the binary tree. Downward means starting from any node and moving only to child nodes. Example: Input → head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3] Output → true Explanation → Nodes in blue form a subpath in the binary tree. 🧠 My Approach: I used recursion to check whether the linked list sequence can be found starting from any node in the binary tree. 1️⃣ For each node in the tree, check if the list starting from `head` matches the downward path from that node. 2️⃣ If not, recursively check the left and right subtrees. 3️⃣ Used a helper function `checkPath()` to verify if a valid path continues as the recursion goes deeper. 💡 What I Learned: ✅ How to combine linked list and binary tree traversal logic ✅ How recursion can efficiently check multiple starting points ✅ Improved my understanding of tree path traversal and backtracking logic #LeetCode #Java #DSA #BinaryTree #LinkedList #CodingUpdate #LearningByDoing
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