🚀Day 89/100 #100DaysOfLeetCode 🧩Problem: Remove Duplicates from Sorted Array II✅ 👩💻Language: Java 💡Approach: Used a two-pointer technique — one pointer (k) keeps track of the next valid index, and the loop iterates through all elements. By checking nums[k - 2], we ensure that each element appears at most twice in the array. 📈Key Takeaways: 🔹Efficient handling of duplicates using conditional checks. 🔹Maintained in-place array modification with O(1) space. 🔹Achieved 100% runtime efficiency! 🧠Performance: ⏱️Runtime: 0 ms (Beats 100%) 💾Memory: 46.83 MB (Beats 31.70%) #100DaysOfLeetCode #Java #CodingJourney #ProblemSolving #LeetCode #CodingChallenge #LeetCode
"Day 89: Remove Duplicates from Sorted Array II in Java"
More Relevant Posts
-
🚀Day 90/100 #100DaysOfLeetCode 🧩Problem: Remove Nth Node From End of List✅ 💻Language: Java 🔍 Approach: Used the two-pointer technique (fast and slow pointers). 1️⃣ Move the fast pointer n steps ahead. 2️⃣ Then, move both fast and slow pointers together until fast reaches the end. 3️⃣ The slow pointer will be just before the node to delete. 4️⃣ Adjust the link to skip the target node. ⚙️Complexity: Time: O(L) (Single traversal) Space: O(1) 📚Key Takeaways: 🔹Using a dummy node handles edge cases smoothly. 🔹The two-pointer method ensures efficient single-pass traversal. 🔹Clean and elegant logic for linked list manipulation. 📊Performance: ⏱️Runtime: 0 ms (Beats 100%) 💾Memory: 42.26 MB (Beats 8.04%) #100DaysOfLeetCode #Java #LeetCode #ProblemSolving #CodingJourney #CodingChallenge
To view or add a comment, sign in
-
-
🚀Day 92/100 #100DaysOfLeetCode 🧩Problem: Swap Nodes in Pairs✅ 💻Language: Java 🔍Approach: 🔹To swap every two adjacent nodes in a linked list, I used a dummy node to simplify pointer handling. 🔹The dummy node helps manage edge cases (like swapping the first pair). 🔹I iteratively swapped pairs by adjusting the next pointers of each node. 🔹Finally, I returned dummy.next as the new head of the list. 🧠Key Takeaways: 🔹Dummy nodes are powerful tools for simplifying linked list manipulations. 🔹Careful pointer tracking ensures no data loss during swaps. 🔹Iterative solutions can be more memory-efficient than recursion in linked lists. ⚙️Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 41.76 MB (Beats 11.86%) #100DaysOfLeetCode #Java #LinkedList #CodingJourney #ProblemSolving #LeetCode #CodingChallenge
To view or add a comment, sign in
-
-
𝗝𝗮𝘃𝗮 𝗧𝗶𝗽: 𝗕𝘂𝘀𝘁𝗶𝗻𝗴 𝗮 𝗖𝗼𝗺𝗺𝗼𝗻 𝗠𝗲𝗺𝗼𝗿𝘆 𝗠𝘆𝘁𝗵 Let's talk about a common assumption in Java: if a short primitive is smaller than an int, then a Short object must be smaller than an Integer object, right? Not exactly. This is a great example of how Java's object model works. While short (2 bytes) is half the size of int (4 bytes), their wrapper classes tell a different story. Every object in Java comes with overhead—a header for metadata. This overhead is often larger than the data itself! On a standard 64-bit system, this header plus memory padding means that Byte, Short, and Integer objects all typically occupy the same 16 bytes of memory. So, what's the lesson? ✅ Use Integer by default: For collections like List<Integer>, it's the standard and doesn't waste memory compared to Short or Byte. ✅ Use Short or Byte for clear communication: They are great for showing that a field has a limited, known range. ✅ For real memory savings, use primitive arrays: A short[] is far more memory-efficient than an ArrayList<Short>. It's a small detail, but understanding it helps us write better, more intentional code. #Java #ProgrammingTips #SoftwareEngineering #CodeQuality #Developer
To view or add a comment, sign in
-
𝗝𝗮𝘃𝗮 𝗧𝗶𝗽: 𝗕𝘂𝘀𝘁𝗶𝗻𝗴 𝗮 𝗖𝗼𝗺𝗺𝗼𝗻 𝗠𝗲𝗺𝗼𝗿𝘆 𝗠𝘆𝘁𝗵 Let's talk about a common assumption in Java: if a short primitive is smaller than an int, then a Short object must be smaller than an Integer object, right? Not exactly. This is a great example of how Java's object model works. While short (2 bytes) is half the size of int (4 bytes), their wrapper classes tell a different story. Every object in Java comes with overhead—a header for metadata. This overhead is often larger than the data itself! On a standard 64-bit system, this header plus memory padding means that Byte, Short, and Integer objects all typically occupy the same 16 bytes of memory. So, what's the lesson? ✅ Use Integer by default: For collections like List<Integer>, it's the standard and doesn't waste memory compared to Short or Byte. ✅ Use Short or Byte for clear communication: They are great for showing that a field has a limited, known range. ✅ For real memory savings, use primitive arrays: A short[] is far more memory-efficient than an ArrayList<Short>. It's a small detail, but understanding it helps us write better, more intentional code. #Java #ProgrammingTips #SoftwareEngineering #CodeQuality #Developer
To view or add a comment, sign in
-
🚀Day 91/100 #100DaysOfLeetCode 🔍Problem: Combination Sum✅ 💻Language: Java 💡Approach: Used Backtracking to explore all possible combinations that sum up to the target. At each step, I either include or skip the current candidate, ensuring no duplicates by maintaining a start index. When the target becomes 0, the current combination is added to the result list. 🧠Key Takeaways: 🔹Backtracking is ideal for exploring multiple decision paths. 🔹Efficient pruning avoids unnecessary recursive calls. 🔹Always clone the current path before adding it to the result to avoid mutation issues. ⚙️Performance: ⏱️Runtime: 2 ms (Beats 84.56%) 💾Memory: 44.65 MB (Beats 64.98%) #100DaysOfLeetCode #Java #Backtracking #LeetCode #ProblemSolving #CodingJourney #CodingChallenge
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Solved Squares of a Sorted Array in Java 🔠 Approach The task was to take an array of integers sorted in non-decreasing order, square each number, and then return the result array also sorted in non-decreasing order. Brute-Force Method The solution implemented here is a straightforward two-step brute-force approach: Squaring: I iterated through the input array nums and replaced each element with its square (i.e., nums[i] * nums[i]). This handles both positive and negative numbers correctly. Sorting: After squaring all elements, I used Java's built-in Arrays.sort(nums) method to sort the entire array. While correct, this approach has a time complexity dominated by the sorting step, which is O(NlogN), where N is the number of elements. The runtime of 10 ms shows that a more efficient, two-pointer approach (which can solve this in O(N) time) is generally preferred for optimal performance. #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Array #Sorting #ProblemSolving
To view or add a comment, sign in
-
-
🚀Day 93/100 #100DaysOfLeetCode 🧩Problem: Remove Duplicates from Sorted List II✅ 💻Language: Java 🧠Approach: This problem requires removing all duplicate nodes from a sorted linked list, leaving only unique elements. Steps: 1️⃣Use a dummy node to handle edge cases easily (like when the first few nodes are duplicates). 2️⃣Use two pointers — one (prev) to track the previous node and another (head) to traverse the list. 3️⃣Whenever duplicate values are found (head.val == head.next.val), move head forward until all duplicates are skipped. 4️⃣Link prev.next to the next distinct node. 5️⃣Move prev forward only when no duplicates are found. This ensures that only unique nodes remain in the resulting linked list. 🔑Key Takeaways: 🔹Handling linked list edge cases effectively using a dummy node simplifies logic. 🔹Two-pointer techniques are powerful for in-place list manipulation. 🔹Proper pointer management avoids unnecessary complexity and extra memory usage. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100%) 💾Memory: 43.51 MB (Beats 24.99%) #100DaysOfLeetCode #Java #LinkedList #LeetCode #CodingJourney #DSA #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 45 of #LeetCode Journey 🚀 ✅ Problem: Count and Say 📘 Language: Java 🔹 Status: Accepted (30/30 test cases passed) 🔹 Runtime: 4 ms | Beats 55.38% 🔹 Memory: 41.86 MB 🧠 Concept: This problem is about generating the n-th term in the “count and say” sequence. Each term is built by describing the previous term — count the number of digits and say them in order. 🧩 Approach: Start with "1". For each iteration, use a StringBuilder to construct the next sequence. Track consecutive digits using a counter. Append the count and digit when the sequence changes. 💡 Efficient string manipulation and iteration give optimal performance. 🔥 Every solved problem builds confidence. One step closer to mastering patterns in strings! #Day45 #LeetCode #Java #CodingChallenge #ProblemSolving #CountAndSay #50DaysOfCode
To view or add a comment, sign in
-
-
Another late-night success Solved a tricky binary search + sliding window problem efficiently in Java, optimizing power distribution logic in minimal runtime. 📊 Runtime: 31 ms 💡 Beats 89.29% of Java submissions 🧩 Concepts used: Binary Search, Prefix Sum, Sliding Window Each accepted solution reminds me that writing clean, efficient code isn’t just about passing tests — it’s about thinking like the system itself. #Java #LeetCode #ProblemSolving #Algorithms #CodingJourney
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