Day 17 of #50DaysOfLeetCode Today’s problem: Move Zeroes (LeetCode) Problem Statement: Move all 0s to the end of the array while maintaining the relative order of non-zero elements — all done in-place. Approach: Used the Two Pointer Technique to efficiently rearrange elements in a single pass without extra space. Key Insight: Track the position of the next non-zero element and swap only when necessary. 🔹 Complexity: - Time: O(n) - Space: O(1) #LeetCode #Java #DataStructures #CodingJourney #ProblemSolving #100DaysOfCode #DeveloperLife
Move Zeroes in Array with Two Pointer Technique
More Relevant Posts
-
🚀 Day 48 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sort Array By Parity Problem Insight: Rearrange the array so that all even numbers come before odd numbers. The order of elements doesn’t matter. Approach: • Used the two-pointer technique (partition logic) • Maintained a pointer j to track the position for even numbers • Traversed the array using i • Whenever an even number is found, swapped it with index j and incremented j • This ensures all even elements move to the front in a single pass Time Complexity: O(n) Space Complexity: O(1) (in-place solution) Key Learnings: • Two-pointer technique is very useful for array partitioning problems • Swapping helps avoid extra space usage • This pattern is similar to problems like moving zeros or segregating positives/negatives Takeaway: Simple logic + optimal approach = clean and efficient solution. Consistency is making these patterns easier to recognize! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀100 Days of Code Day-26 LeetCode Practice – Remove Duplicates from Sorted Array Solved a classic problem using the Two Pointer Technique 💡 📌 Problem: Given a sorted array, remove duplicates in-place and return the number of unique elements. 🔍 Key Idea: Since the array is sorted, duplicates are adjacent. Using two pointers helps efficiently overwrite duplicates without extra space. ⚡ Complexity: Time → O(n) Space → O(1) 💻 Clean and optimized approach makes this problem a great example of in-place array manipulation! #LeetCode #Java #DataStructures #CodingPractice #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode – Unique Binary Search Trees II Today’s problem was all about generating all structurally unique BSTs for values from 1 to n. At first glance, it feels tricky because it's not just counting trees — we actually need to build every possible tree structure. 💡 Key Insight: Pick each number i as the root Recursively build: Left subtree from [1 ... i-1] Right subtree from [i+1 ... n] Combine every left & right subtree pair 🌳 This is a classic Recursion + Backtracking problem and is closely related to Catalan Numbers. 📌 Example: For n = 3, we get 5 unique BSTs ⚡ What I learned today: How recursion can generate combinations of structures Importance of base case (start > end → null) Combining subproblems effectively 💻 Time Complexity: Approximately O(4ⁿ / √n) Consistency is key — 90 days strong and still going 💪 Next target: 💯 #DSA #Java #LeetCode #Recursion #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 54 of my #100DaysOfCode Journey Today, I solved LeetCode – Sort Array By Parity II Problem Insight: Rearrange the array such that even-indexed positions have even numbers and odd-indexed positions have odd numbers. Approach: • Created a new result array of same size • Used two pointers: evenplace = 0 and oddplace = 1 • Traversed the array once • Placed even numbers at even indices and odd numbers at odd indices • Incremented pointers by 2 to maintain correct positions Time Complexity: O(n) | Space Complexity: O(n) Key Takeaway: Using two pointers for index placement makes the solution clean, efficient, and avoids unnecessary swaps. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🔥 Today’s DSA Update— #Day58 #MonotonicStack Today I worked on finding Next Greater Element I (Leetcode 496). 💡 What I understood This pattern is useful for problems where we need to find things like: 1. Next greater element 2. Next smaller element Instead of using nested loops (which take O(n²)), we can solve it in O(n) using a stack. 💡 The key idea We use a stack to keep elements that are still “waiting” for their answer. When we find a bigger element: 1. We pop all smaller elements from the stack 2. For each popped element, we now know its next greater value 3. Each element is pushed and popped only once. 🧠 What I learned today Today’s lesson was that stacks are not just for push and pop operations — they can be used to store state while processing elements. This pattern feels different from normal array traversal because we are managing a “waiting list” of elements. #Java #DSA #Stack #DataStructures #LeetCode #ConsistencyCurve
To view or add a comment, sign in
-
-
🚀 Day 52 of #100DaysOfLeetCode Solved: Daily Temperatures (Monotonic Stack) Today’s focus was on understanding how to optimize from a brute-force O(n²) approach to an efficient O(n) solution using a stack. Key takeaways: Learned how to identify “next greater element” patterns Understood how monotonic stacks help avoid redundant work Practiced writing clean and optimized code Consistency is starting to pay off. Onto the next one. #DSA #Java #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Solved the Remove Duplicates from Sorted Linked List problem using iterative traversal. The idea is to traverse the list and compare current node with next node. If values are same, skip the duplicate node by adjusting pointers; otherwise move forward. Since the list is sorted, duplicates are always adjacent, making it efficient. Time Complexity: O(n) Space Complexity: O(1) #Java #DSA #LinkedList #LeetCode #Coding
To view or add a comment, sign in
-
-
🚀 Day 36 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Longest Common Prefix Problem Insight: Find the longest common prefix among an array of strings. If no common prefix exists, return an empty string. Approach: • Assume the first string as the initial prefix • Iterate through the remaining strings • While the current string doesn’t start with the prefix: – Trim the last character of the prefix • Repeat until a common prefix is found or it becomes empty Time Complexity: • O(n × m) — n = number of strings, m = length of prefix Space Complexity: • O(1) — constant extra space Key Learnings: • Reducing the problem step-by-step makes it easier to solve • Shrinking the prefix is often more efficient than building it • Edge case handling (like empty arrays) is crucial Takeaway: Sometimes the best approach isn’t to construct a solution, but to refine it until it fits perfectly. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Strings
To view or add a comment, sign in
-
-
🚀 Day 9/30 — LeetCode Challenge Solved a problem on LeetCode involving "mirror distance of a number" The task was to reverse the digits of a number and compute the absolute difference with the original value. ✅ Key takeaway: Simple problems still reinforce core concepts like "digit manipulation and number handling" Consistency continues. #LeetCode #Java #ProblemSolving #Consistency
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