Day 21 of #100DaysOfLeetCode 💻✅ Solved #27. Remove Element problem on LeetCode in Java. Approach: • Used a two-pointer technique to modify the array in-place • Maintained a pointer k to place elements not equal to val • Iterated through the array and skipped elements equal to val • Placed non-val elements at the k-th position and incremented k • Returned k as the number of remaining elements Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 44 MB (Beats ~75% submissions) Key Learning: ✓ Strengthened understanding of in-place array manipulation ✓ Learned how to skip unwanted elements efficiently ✓ Improved confidence in two-pointer techniques for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
Java Solution for LeetCode #27: Remove Element
More Relevant Posts
-
Day 68 of #100DaysOfCode 🚀 Today I implemented Pascal’s Triangle using Java. At first glance, it looks like just a pattern problem. But internally, it teaches something powerful — building current state from previous state. 🔹 The first and last elements of every row are always 1 🔹 Every middle element = sum of two elements from the previous row 🔹 This is a classic example of bottom-up thinking Instead of hardcoding values, we dynamically generate each row based on the previous one. This problem strengthened: Nested loop understanding 2D List handling in Java Pattern recognition Thinking in terms of recurrence Small problems. Strong foundations. Consistent progress. On to the next one 💪 #100DaysOfCode #Java #DSA #ProblemSolving #LearningInPublic #dsawithkunal
To view or add a comment, sign in
-
-
Day 23 of #100DaysOfLeetCode 💻✅ Solved #19. Remove Nth Node From End of List on LeetCode using Java. Approach: • Used a dummy node to handle edge cases (like removing the head) • Initialized two pointers: fast and slow • Moved fast pointer n+1 steps ahead to maintain a gap • Traversed both pointers together until fast reached null • Slow pointer stopped just before the node to delete • Updated links to remove the target node in one pass Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.77 MB Key Learning: ✓ Mastered two-pointer (fast & slow) technique ✓ Understood importance of dummy node for edge cases ✓ Solved the problem in a single traversal (O(n) time, O(1) space) Consistency is building confidence 🚀 #Java #LeetCode #DSA #LinkedList #TwoPointers #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 39 of #100DaysOfLeetCode 💻✅ Solved #258. Add Digits problem in Java. Approach: • Used a loop to repeatedly add all digits of the number • Extracted each digit using modulus (%) and divided the number by 10 • Stored the digit sum and repeated the process until the result became a single digit • Returned the final single digit as the answer Performance: ✓ Runtime: 1 ms (Beats 97.92% submissions) ✓ Memory: 42.52 MB Key Learning: ✓ Practiced digit extraction using modulus and division ✓ Understood how to repeatedly reduce a number to a single digit ✓ Strengthened problem-solving using loops and basic number manipulation Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14/100 – LeetCode Challenge 🚀 Problem: #169 Majority Element Difficulty: Easy Language: Java Approach: Sorting + Middle Element Time Complexity: O(n log n) Space Complexity: O(1) 🔍 Key Insight: The majority element appears **more than ⌊n / 2⌋ times** in the array. If we **sort the array**, the majority element must occupy the **middle position** because it appears more than half of the time. Therefore, the element at index **n/2** will always be the majority element. 🧠 Solution Brief: First sorted the array using `Arrays.sort()`. Since the majority element appears more than half of the array length, it will always be positioned at the middle index. Finally returned `nums[nums.length / 2]` as the majority element. 📌 What I Learned: Understanding problem constraints can simplify the solution significantly. Sometimes a simple observation (like majority occupying the middle after sorting) can avoid more complex implementations. #LeetCode #Day14 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 26 of #100DaysOfLeetCode 💻✅ Solved #203. Remove Linked List Elements on LeetCode using Java. Approach: • Handled edge cases by removing matching nodes from the beginning of the list • Traversed the linked list using a pointer • Checked the next node’s value instead of the current node • If value matched, updated links to skip the node • Maintained in-place modification without using extra data structures Performance: ✓ Runtime: 1 ms (Beats 95.94% submissions) ✓ Memory: 47.62 MB Key Learning: ✓ Improved understanding of linked list pointer manipulation ✓ Learned how to handle head node edge cases carefully ✓ Strengthened in-place deletion logic in singly linked lists Learning one problem every single day 🚀 #Java #LeetCode #DSA #LinkedList #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 27 of #100DaysOfLeetCode 💻✅ Solved #83. Remove Duplicates from Sorted List on LeetCode using Java. Approach: • Utilized the fact that the linked list is already sorted • Traversed the list using a single pointer • Compared current node value with next node value • If duplicate found, skipped the next node by updating links • Continued traversal until reaching the end of the list Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 45.30 MB (Beats 85.70% submissions) Key Learning: ✓ Understood how sorting simplifies duplicate removal logic ✓ Strengthened pointer manipulation skills in linked lists ✓ Learned efficient in-place modification without extra space Learning one problem every single day 🚀 #Java #LeetCode #DSA #LinkedList #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 30/100 - LEETCODE Challenge ✅ Problem : Ransom Note Solved the Ransom Note problem using Java! I implemented an efficient approach using a frequency array to count the occurrences of each character in the magazine string and then reduced the count while checking the ransomNote string. If any character count becomes negative, it means the magazine does not have enough letters to construct the ransom note. This solution runs in O(n + m) time complexity with constant space (26 letters), making it highly optimized. ✅ Runtime: 1 ms (Beats 99.85%) ✅ Memory: 46.31 MB Great practice for understanding character frequency, arrays, and greedy checking techniques in string problems. #100DaysOfCode #java #Coding #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 24 of #100DaysOfLeetCode 💻✅ Solved #35. Search Insert Position on LeetCode using Java. Approach: • Applied Binary Search to achieve O(log n) time complexity • Initialized two pointers: left and right • Calculated mid using left + (right - left) / 2 to avoid overflow • Compared mid element with target to adjust search space • If target not found, returned left as the correct insert position Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.2 MB Key Learning: ✓ Strengthened understanding of Binary Search pattern ✓ Learned how to determine insert position when element is absent ✓ Improved confidence in handling sorted array problems efficiently Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 29 of #100DaysOfLeetCode 💻✅ Solved #22. Generate Parentheses on LeetCode using Java. Approach: • Used Backtracking to generate all valid combinations • Added "(" only if open brackets were available • Added ")" only when close brackets were greater than open • Ensured at every step that the parentheses remain balanced • Stopped recursion when both open and close counts reached zero Performance: ✓ Runtime: 3 ms (Beats 16.29% submissions) ✓ Memory: 45.18 MB (Beats 13.87% submissions) Key Learning: ✓ Strengthened understanding of Backtracking technique ✓ Learned how to maintain constraints during recursion ✓ Improved ability to build combinations using decision trees Learning one problem every single day 🚀 #Java #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🪨📺 Even early humans knew the importance of good logic! From stone caves to Java code — the idea is timeless. This logic demonstrates an efficient way to compute the sum of (n-1) elements by: Calculating the total sum once Subtracting one element at a time instead of using nested loops Simple. Clean. Optimized. Because whether it’s early humans discovering fire 🔥 or developers optimizing code ⚙️ — good logic always survives the ages. #Java #ProgrammingLogic #DSA #ProblemSolving #CodingLife #LearningByDoing #TechHumor
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