📌 Day 1/100 – #100DaysOfDSA Started my journey today with a classic problem from LeetCode: 🔍 Problem: Remove Duplicates from Sorted Array 🧠 What I learned: How to use the two-pointer technique efficiently Instead of extra space, we can modify the array in-place Helps reduce time complexity to O(n) and space to O(1) ✅ Solution Approach: Used two pointers — one to track unique elements and another to traverse the array 👣 Whenever a new unique element is found, it gets placed in the correct position. 💡 Key Insight: When the array is sorted, duplicates are always adjacent — making this problem much simpler! ⚡ Takeaway: Two-pointer technique is powerful for array problems — definitely a pattern to remember. Excited to stay consistent and improve every day 🚀 If you're also doing #100DaysOfDSA, let’s connect and grow together 🤝 #100DaysOfDSA #DataStructures #Algorithms #Programming #SoftwareEngineering #CodingChallenge #LeetCode #DeveloperJourney #TechJourney #ComputerScience #ProblemSolving #Coding
Remove Duplicates from Sorted Array with Two-Pointer Technique
More Relevant Posts
-
Day 97/100 – DSA Challenge 🚀 Topic: Z algorithm Key Learning: One powerful yet underrated technique is the Z Algorithm. What is the Z Algorithm? The Z Algorithm is a linear-time string matching algorithm that constructs a Z-array, where each element represents the length of the longest substring starting from that position that matches the prefix of the string. GitHub: <https://lnkd.in/dtek96E3> #100DaysOfDSA #ProblemSolving #LinkedInLearning #clanguage #coding #programming #developer #softwareengnieer #datastructure
To view or add a comment, sign in
-
-
Day 76 on LeetCode Arranging Coins 🪙✅ Keeping the streak alive during mid exams — focusing on clarity and consistency over complexity 💯 🔹 Approach Used in My Solution The goal was to find how many complete rows of coins can be formed. Key idea: • Start placing coins row by row • For each row i, subtract i coins from n • Continue until n is no longer enough to fill the next row • Return the number of fully completed rows This is a simple simulation approach that directly models the problem. ⚡ Complexity: • Time Complexity: O(√n) (since rows grow incrementally) • Space Complexity: O(1) 💡 Key Takeaways: • Sometimes simulation is the most intuitive solution • Practiced handling problems involving incremental patterns • Reinforced staying consistent even during busy schedules 🔥 Progress may be small, but consistency builds momentum. #LeetCode #DSA #Algorithms #DataStructures #Math #Simulation #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
📌 We learn stacks as a simple concept: Last In, First Out 👉 That makes it easier to recognize using stack as a pattern for problems such as “Parantheses matching” or “Undo/Redo” But then you come across a problem like Daily Temperatures 🌡️ Why would you even think of using a stack here? 🤷♀️ And more importantly — how? 🤔 That’s where the idea of a “Monotonic stack” comes in. 📌 Instead of using a stack just for insertion order, we use it to maintain a condition. 👉 Elements are kept in a specific order (increasing or decreasing) 👉 The moment that order is violated, we start popping So the stack isn’t just storing elements — it’s helping us eliminate unnecessary comparisons and keep only what’s useful ✔️ And that shift is what makes the solution efficient ⚡ Why this problem captures my interest is because: 👉 Not every problem clearly signals the pattern you need, the real skill is identifying which structure helps you track and optimize information efficiently👍 #softwareengineering #leetcode #algorithms #dsa #stack #coding #programming #problemSolving #computerscience
To view or add a comment, sign in
-
-
55 of #100DaysOfCode: Today I dived into LeetCode 316 (Remove Duplicate Letters). This problem is a fantastic lesson in balancing multiple constraints: maintaining unique characters while ensuring the smallest lexicographical order. The Key Insight: Using a Monotonic Stack approach. The goal isn't just to remove duplicates, but to greedily decide whether to keep a character or pop it based on whether it appears again later in the string. Stack Logic: Pop elements only if they are larger than the current character AND guaranteed to appear later. #cpp #leetcode #programming #algorithms #datastructures #codingcommunity #100daysofcode
To view or add a comment, sign in
-
-
Day 86 on LeetCode Swapping Nodes in a Linked List 🔗🔄✅ Continuing the linked list journey with another pointer-based thinking problem 💯 🔹 Swapping Nodes in a Linked List The goal was to swap the kth node from the beginning with the kth node from the end. 🔸 Approach Used in My Solution • First, traverse the list to find the total length • Compute the position from the end → k_reverse = n - k + 1 • Traverse again to locate both nodes (swap1 and swap2) • Swap their values instead of changing pointers This keeps the implementation simple while solving the problem correctly. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Learned how to handle relative positions from start and end • Swapping values can simplify problems where pointer manipulation gets complex • Reinforced multi-pass traversal when needed for clarity 🔥 Step by step building stronger intuition for linked list problems. #LeetCode #DSA #Algorithms #DataStructures #LinkedList #Pointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Recover the Tree ?? by providing water! Approach (Recover BST) Do inorder traversal (BST should be sorted) Track previous node If order breaks (prev > current), it’s a violation First violation: first = prev middle = current Second violation (if exists): last = current Time Complexity: O(n) → you traverse all nodes once using inorder Space Complexity: O(h) → recursion stack (h = height of tree) Worst case (skewed tree): O(n) Best case (balanced tree): O(log n) #LeetCode #DSA #DataStructures #Algorithms #Coding #Programming #binarysearchtree
To view or add a comment, sign in
-
-
In LeetCode 867 – Transpose Matrix Today I worked on a basic but important matrix problem: transposing a matrix. The idea is simple — convert rows into columns. Understanding matrix traversal helps build a strong foundation for more complex problems. #LeetCode #DSA #Coding #Programming #ProblemSolving #100DaysOfCode #DeveloperJourney #CodeNewbie #Tech #Learning #CodingLife #ComputerScience #Algorithms #Matrix #Consistency
To view or add a comment, sign in
-
-
Cycle Sort is not just another sorting algorithm, it is provably impossible to do fewer writes. Period. Cycle Sort follows where each element belongs, places it, picks up the displaced one, and follows that element. It continues chain after chain until every cycle closes. This is group theory disguised as a sorting algorithm. By minimizing writes to memory, Cycle Sort achieves the theoretical lower bound, making it optimal for scenarios where write operations are expensive, such as flash memory or EEPROM storage. Every element moves directly to its final position with no unnecessary swaps, proving that sometimes the most elegant solution is also the most mathematically efficient. #CycleSort #Programming #CodingLife #TechEducation #Algorithms #SortingAlgorithm #GroupTheory #OptimalAlgorithm #MemoryEfficient #ComputerScience #WriteOptimized #AlgorithmDesign #Coding #Developer #TechLearning #DataStructures #ProgrammingLife #CodeSmart #AlgorithmArt #ProvablyOptimal
To view or add a comment, sign in
-
Day 65 on LeetCode Sort Characters By Frequency 🔤📊✅ Today’s problem focused on combining hash maps with custom sorting. 🔹 Approach Used in My Solution The goal was to sort characters in a string based on their frequency in descending order. Key idea in the solution: • Use a hash map to count frequency of each character • Store (character, frequency) pairs in a vector • Apply custom sorting based on frequency (descending order) • Build the result string by repeating characters according to their frequency This approach efficiently organizes characters by importance (frequency). ⚡ Complexity: • Time Complexity: O(n log n) (due to sorting) • Space Complexity: O(n) 💡 Key Takeaways: • Practiced frequency counting using hash maps • Learned how to apply custom comparators in sorting • Reinforced building results based on frequency-driven logic #LeetCode #DSA #Algorithms #DataStructures #HashMap #Sorting #Strings #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
49 of #100DaysOfCode Solved Next Greater Element II (LeetCode 503) using a Monotonic Stack + Circular Traversal approach 🔁 💡 Approach: Since the array is circular, we iterate 2 × n times to simulate wrapping around. Use a stack to store indices whose next greater element hasn’t been found yet. Traverse from left to right: If the current element is greater than the element at the index on top of the stack → update result. Keep popping until the stack condition breaks. Only push indices during the first pass (i < n) to avoid duplicates. ⚡ Key Insight: Using a monotonic decreasing stack helps us efficiently track elements waiting for their next greater value — reducing unnecessary comparisons. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(n) #LeetCode #DSA #Coding #Cpp #Programming #Stack #InterviewPrep
To view or add a comment, sign in
-
Explore related topics
- LeetCode Array Problem Solving Techniques
- Leetcode Problem Solving Strategies
- Approaches to Array Problem Solving for Coding Interviews
- Solving Sorted Array Coding Challenges
- How to Use Arrays in Software Development
- Methods to Remove Outliers from Data Arrays
- How to Improve Array Iteration Performance in Code
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