🎯 Day 82 of #100DaysOfCode – LeetCode 137: Single Number II Today’s challenge was about identifying the unique number in an array where every element appears three times except for one. 🧩 Problem Statement: Given an integer array nums, where every element appears exactly three times except for one, find that single element that appears only once. Example: Input: [2,2,3,2] Output: 3 💭 Approach 1: Using HashMap At first, I solved this using a HashMap to count the frequency of each number. Traverse the array and store each element’s occurrence. Return the element whose count equals 1. 🕒 Time Complexity: O(n) 💾 Space Complexity: O(n) 🚀 Key Takeaway: Sometimes, the best way to optimize is not by adding more data structures, but by understanding how data behaves at the bit level. #100DaysOfCode #Day82 #LeetCode #Java #ProblemSolving #DSA #CodingJourney #BitManipulation #KeepLearning
Solved LeetCode 137: Single Number II with HashMap in Java
More Relevant Posts
-
🚀 Just Solved LeetCode #102 — Binary Tree Level Order Traversal 📘 Problem: Given the root of a binary tree, return the level order traversal of its nodes' values — meaning, traverse the tree level by level from left to right. Example: Input → [3,9,20,null,null,15,7] Output → [[3], [9,20], [15,7]] 🧠 My Approach: I solved this using a recursive approach instead of the usual queue-based BFS. 1️⃣ First, I calculated the total number of levels in the tree using recursion. 2️⃣ Then, for each level, I called a helper function `nThLevel()` to collect all nodes at that level. 3️⃣ I stored each level’s nodes in a separate list and finally returned a list of lists as the result. This approach helped me deeply understand the relationship between recursion depth and tree levels. 💡 What I Learned: ✅ Different ways to perform level order traversal — BFS vs recursion. ✅ How to effectively use recursion to explore each tree level. ✅ Improved understanding of function calls, base conditions, and data storage in recursive algorithms. #LeetCode #Java #DSA #BinaryTree #CodingJourney
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 76 Insert a Node in a Doubly Linked List Problem: Given a position p and a value x, insert a new node with data x after the p-th node (0-based indexing) in a doubly linked list. Example: Input: p = 2, x = 6 Output: 2 <-> 4 <-> 5 <-> 6 My Approach: Traversed to the p-th node using a simple loop. Updated pointers of the prev and next nodes carefully to maintain bidirectional linkage. Handled edge cases for insertion at the end of the list. Time Complexity: O(N) Space Complexity: O(1) Understanding pointer manipulation in linked lists builds a strong base for advanced data structure problems like deletion, reversal, and flattening of linked lists. #takeUforward #100DaysOfCode #DSA #Java #ProblemSolving #GeeksForGeeks #LinkedList #Pointers #CodingChallenge #CodeNewbie #LearningEveryday
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 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 19/100 – Design HashMap (LeetCode 706) 🔹 Problem: Design a basic HashMap data structure without using built-in hash table libraries. Implement methods to put, get, and remove key-value pairs efficiently. 🔹 Approach: Used a direct array-based mapping for keys up to 1,000,000. Initialized all values to -1 to mark absence of mappings. Implemented: put(key, value) → stores/updates the value. get(key) → returns the mapped value or -1 if absent. remove(key) → resets the key’s value to -1. 🔹 Key Learning: Reinforced understanding of hashing fundamentals and key-value mapping. Learned how to simulate data structures without built-in utilities. Understood the trade-off between memory and simplicity in design. A simple yet powerful reminder that sometimes brute structure works best! 💡 #100DaysOfCode #Day19 #LeetCode #Java #DSA #ProblemSolving #HashMap #CodingJourney
To view or add a comment, sign in
-
-
✨ Day 56 of 100: Remove Duplicates from Sorted List II ✨ Today’s challenge was LeetCode 82 – Remove Duplicates from Sorted List II 🧩 Problem: Given a sorted linked list, delete all nodes that have duplicate numbers — leaving only distinct numbers from the original list. Example: Input: 1 -> 2 -> 3 -> 3 -> 4 -> 4 -> 5 Output: 1 -> 2 -> 5 Approach: 🔹 Use a dummy node to handle edge cases easily (like when the first few nodes are duplicates). 🔹 Traverse the list using two pointers (prev and current). 🔹 If duplicates are found (i.e., current.val == current.next.val), skip all nodes with that value. 🔹 Otherwise, move prev forward. This approach ensures all duplicate sequences are fully removed, not just reduced. 💡 Key Takeaways: The dummy node trick simplifies edge case handling. Mastered pointer manipulation in linked lists. Reinforced understanding of data cleanup in sorted sequences. #100DaysOfCode #Day56 #LeetCode #Java #LinkedList #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
Day42/100 #leetcodegrind I successfully implemented a Stack using Queues 💪 It was an amazing problem that helped me deeply understand how data structures work internally. 📚 Key takeaways: Used Queue (FIFO) to mimic Stack (LIFO) behavior Learned how to rotate queue elements after each push Improved my understanding of time complexity and order of operations Every small step builds a strong foundation for mastering DSA 💡 #DSA #Java #CodingJourney #ProblemSolving #Stack #Queue #LeetCode #100DaysOfCode #LearningInPublic
To view or add a comment, sign in
-
-
Day 20 – Variables & Primitive Data Types (Memory-Level Understanding) Today, I explored how variables and primitive data types work internally in Java — beyond just syntax. 🔹 Key Learnings: - Stack vs Heap Memory: - Stack stores primitive values and references. - Heap stores actual objects and instance data. Primitive Data Types: - int, byte, short, long → store integer values. - float (32-bit) and double (64-bit) → stored using IEEE 754 format (sign, exponent, mantissa). - char → 2 bytes (Unicode). boolean → true/false (JVM dependent). Float vs Double: - Float → ~7 digits precision - Double → ~15 digits precision - Variable Scope & Lifetime: - Local → within a method. - Instance → within an object. - Static → shared across all objects. 🔹 Takeaway: Understanding how Java handles variables in memory helps write more efficient and predictable code — especially when dealing with references and object lifetimes. #Java #LearningJourney #Day20 #Variables #DataTypes #MemoryManagement
To view or add a comment, sign in
-
🚀 Just implemented a custom Vector<T> class in Java — a dynamic array structure that grows automatically as elements are added. It supports key operations like push_back, pop_back, front, back, clear, and more — all while practicing the concepts of generics, dynamic memory allocation, and data encapsulation. Rebuilding core data structures from scratch is a great way to understand how tools like ArrayList work internally. 💻 #Java #DSA #LearningByDoing #CodingJourney #DataStructures Nohit Singh,Shreyash Khedekar,Anshuman Singh,Arpit Jain
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
-
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