🚀 End of the Week LeetCode Practice Wrapping up this week’s coding practice with another problem from the array collection on LeetCode: Remove Duplicates from Sorted Array. It’s the end of the week, and I’m glad to say I’ve already knocked down 2 problems while continuing to sharpen my problem-solving skills. 🔎 Problem Overview Given a sorted array, the task is to remove duplicates in-place so that each element appears only once. The function should return the number of unique elements (k), and the first k positions of the array should contain those unique values. The challenge is doing this without using extra space, meaning we must modify the original array efficiently. 🧠 Approach Because the array is already sorted, duplicate values appear next to each other. This makes the two-pointer technique a clean and efficient solution. • Pointer i tracks the position of the last unique element • Pointer j scans through the array • When a new unique value appears, i moves forward and we update the array This keeps the solution efficient with: • Time Complexity: O(n) • Space Complexity: O(1) ⚙️ Performance • Runtime: 4 ms (Beats 42.04%) • Memory Usage: 13.92 MB (Beats 38.66%) 💡 I’ve featured the full implementation in my LeetCode library on my LinkedIn profile, where I’m documenting my problem-solving journey. Feel free to check it out there. 📊 Week Summary ✔ Solved 2 LeetCode problems ✔ Practiced array manipulation and pointer techniques ✔ Continued building consistency in coding practice Now it's time to reset, recharge, and start getting ready for next week’s challenge. #LeetCode #Algorithms #Python #DataScienceJourney #MachineLearning #CodingPractice #ProblemSolving
Remove Duplicates from Sorted Array on LeetCode
More Relevant Posts
-
Headline: 🚀 From Confused to Confident: Solving LeetCode 2906! Body: Ever stared at a problem statement and thought, "Where do I even start?" That was me today with LeetCode 2906: Construct Product Matrix. The task seemed simple: For every cell in a matrix, calculate the product of all other elements. But the catch? Doing it efficiently without hitting a Time Limit Exceeded (TLE) error. 💡 The Breakthrough: I realized this is essentially a 2D version of the classic "Product of Array Except Self." Instead of brute-forcing it (which would be O(N²)), I used the Prefix & Suffix Product approach. 🎓 How I visualized it (The Story): Imagine a classroom photo where every student needs to calculate the "score" of everyone else except themselves. 1️⃣ Forward Pass: Calculate the product of everyone standing to your left. 2️⃣ Backward Pass: Calculate the product of everyone standing to your right. 3️⃣ Multiply: Left × Right = Your Answer! By treating the 2D matrix as a continuous stream, I optimized the solution to: ✅ Time Complexity: O(m × n) ✅ Space Complexity: O(1) (excluding output matrix) 🔑 Key Takeaway: Don't rush to code. Spend time visualizing the data flow. Sometimes, breaking a 2D problem into a 1D logic stream makes all the difference. Has anyone else tackled this problem? What was your approach? Let's discuss in the comments! 👇 #LeetCode #DSA #Coding #ProblemSolving #SoftwareEngineering #LearningJourney #Python #Algorithms #TechCommunity
To view or add a comment, sign in
-
-
Hello dudes and dudettes!! 🚀 Day 11/150 — Cracked LeetCode 274: H-Index Today’s problem was less about coding… and more about thinking smart 😄 At first glance, it looks like just another array problem. But once I dug in, I realized it’s actually about measuring impact — not just numbers. 🔍 What’s the Problem About? You’re given an array where each number represents how many times a research paper was cited. Now the twist: 👉 You need to find the H-Index Which basically means: A researcher has an H-Index of h if they have h papers with at least h citations each. 🧠 The “Aha!” Moment Initially, it feels confusing… like, “Where do I even start?” But everything clicks when you: 👉 Sort the array in descending order Suddenly, the problem becomes super clean. Now it’s just about checking: “Do I have 1 paper with ≥1 citation?” “Do I have 2 papers with ≥2 citations?” “Do I have 3 papers with ≥3 citations?” …and so on. The moment this condition fails — boom, you stop. That’s your answer. 📊 Quick Example Input: [3, 0, 6, 1, 5] After sorting: [6, 5, 3, 1, 0] Now checking step-by-step: 1 paper → valid ✅ 2 papers → valid ✅ 3 papers → valid ✅ 4 papers → not valid ❌ 🎯 Final Answer: 3 💡 What Made This Problem Interesting? It’s not about checking everything — it’s about knowing when to stop A simple sort can completely change how you see the problem It teaches you to think in terms of thresholds and consistency, not just values 😎 My Takeaway This problem is a perfect reminder that: “Sometimes the smartest solution isn’t more work… it’s better perspective.” 🔥 One more step forward in the journey. Let’s keep building. #LeetCode #Algorithms #ProblemSolving #CodingJourney #100DaysOfCode #Python #LearningInPublic
To view or add a comment, sign in
-
-
Today I learned that not all loops are the same and it actually blew my mind.I'm not going to lie. I thought a loop was just a loop.Turns out, there's a whole world in there. Here's what I uncovered today: 🔹 for loop → when you already know how many times you need to repeat something. Clean, predictable, in control. 🔹 while loop → when you don't know how many times, you just keep going until a condition is met. A little unpredictable just like real life. 🔹 while True → runs forever until YOU decide to stop it. At first it scared me. Then I realized how powerful that actually is. 🔹 Nested loops → a loop inside a loop. Each one exists for a reason. Choosing the right loop isn't just about making code work it's about making it make sense. That's the part nobody tells you when you start coding. It's not just logic. It's judgment. Still a beginner. Still figuring it out. But days like today remind me why I started. #Python #Loops #LearningToCode #CodingJourney #PythonProgramming #GrowthMindset #TechCommunity
To view or add a comment, sign in
-
Recently tried using Spec Kit on an office project for Human Managed and it's been a pretty interesting shift in how I approach building pipelines. Instead of jumping straight into writing code, you define the spec first. What the pipeline needs to do, the inputs, outputs, and acceptance criteria. From there, I used it to generate Python scripts for Dagster and the structured approach made a noticeable difference. A few things that stood out: - Clearer intent before writing a single line - Test scenarios defined upfront, not as an afterthought - Easier to revisit and adjust without losing context One thing I didn't expect was how much more token efficient it is compared to vibe coding. With vibe coding you're constantly re-explaining context, correcting drift, and prompting back and forth. Spec Kit handles that through its constitution, a set of rules, conventions, and standards defined once that the AI follows throughout. Less repetition, less waste, more focused output. It's not magic. You still need to review and validate what comes out. But having a spec as the foundation keeps things more predictable and easier to maintain. If you're working with Dagster or similar pipeline tools, worth exploring how a spec-driven approach fits into your workflow. #HumanManaged #SpecKit #Dagster #Data #Python #DevTools
To view or add a comment, sign in
-
Day 10: 90-Day Coding Challenge 🚀 Continuing the journey by strengthening my fundamentals in array-based problems and improving problem-solving efficiency. Today’s problem focused on the classic Two Sum problem. The goal was to find two indices in an array such that their values add up to a given target. At first, a brute-force approach using nested loops works, but it results in O(n²) time complexity, which is not efficient for larger inputs. Instead, I used an optimized approach with a HashMap (dictionary): • Iterated through the array once • Stored each number along with its index • Checked if the complement (target - current number) already exists • Returned the indices as soon as a match is found This approach reduces the time complexity to O(n) with O(n) space complexity. Today’s learning highlights: ✅ Understood the importance of optimizing brute-force solutions ✅ Learned how HashMaps improve lookup efficiency ✅ Strengthened problem-solving with single-pass solutions ✅ Improved thinking in terms of time vs space trade-offs Simple problems like these are great for building strong fundamentals and efficient thinking 💡 Excited to keep the momentum going! #90DaysOfCode #DataStructures #Algorithms #Python #CodingJourney #Arrays #HashMap
To view or add a comment, sign in
-
Day 9: 90-Day Coding Challenge 🚀 Continuing the journey by exploring more tree-based problems and sharpening my understanding of tree properties. Today’s problem focused on checking whether a Binary Tree is a Binary Search Tree (BST). The goal was to verify if the tree satisfies the BST property across all nodes. At first, it might seem enough to compare each node with its immediate children, but that approach fails for deeper levels in the tree. Instead of relying on local comparisons, I used a recursive Depth-First Search (DFS) approach: • Maintained a valid range (min, max) for each node • Ensured every node’s value lies within its allowed limits • Updated the range while moving left and right in the tree • Base case: return True when reaching a null node This approach ensures an efficient solution with O(n) time complexity, where n is the number of nodes. Today’s learning highlights: ✅ Understood the importance of global constraints in trees ✅ Strengthened recursive thinking with range-based validation ✅ Learned why local checks can lead to incorrect solutions ✅ Improved problem-solving approach for tree validation problems Tree problems continue to challenge logical thinking and recursion skills — another great step forward in the journey 💡 Excited to keep the momentum going! #90DaysOfCode #DataStructures #Algorithms #Python #CodingJourney #Recursion #BinaryTree
To view or add a comment, sign in
-
I just built my first Coding Agent as part of my Zera Virtual Assistant project. It's CLI-based for now and it can: - Read and analyze a single coding file - Write and edit code - Get file info from the directory - Run Python files - Resolve small bugs on its own Next step is attaching it to Zera's UI. Demo video attached. Building this helped me understand the real difference between a plain LLM and an LLM Agent. A plain LLM just answers questions. An LLM Agent takes actions, uses tools, and loops until the task is done. Special thanks to freeCodeCamp and Hitesh Choudhary for making these concepts click. If you are getting into AI Agents, just start building. Even a small CLI tool teaches you more than hours of tutorials. #AI #LLMAgents #Python #CodingAgent #VirtualAssistant #BuildInPublic
To view or add a comment, sign in
-
🚀 LeetCode Practice – Another Problem Down Another problem down from the array collection on LeetCode: Remove Element. This one was relatively easy, but it’s all about making consistent progress and staying disciplined with daily practice. 🔎 Problem Overview Given an array nums and a value val, the task is to remove all occurrences of val in-place and return the number of remaining elements. The key constraint is to do this without using extra space, modifying the original array efficiently. 🧠 Approach I used a simple and effective two-pointer technique: • Pointer i scans through the array • Pointer j keeps track of the position to place the next valid element • If the current element is not equal to val, we overwrite at index j and move forward This keeps the solution clean and efficient: • Time Complexity: O(n) • Space Complexity: O(1) ⚙️ Performance • Runtime: 0 ms (Beats 100%) • Memory Usage: 12.51 MB (Beats 12.63%) 💡 Full implementation is available in my featured LeetCode library on my LinkedIn profile—documenting the journey step by step. 📊 Reflection It may be a simpler problem, but this is where discipline, consistency, and momentum are built. Another problem down. Staying consistent. A lot more to come. ❓ Quick question for the community: Do you guys recommend any other approach for this problem, or any optimization I should explore? #LeetCode #Algorithms #Python #CodingJourney #Consistency #Discipline #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 14 of 100 Days LeetCode Challenge Problem: The K-th Lexicographical String of All Happy Strings of Length n Today’s problem is a perfect blend of Backtracking + Lexicographical Ordering 🔥 💡 Key Insight: A happy string: Uses only 'a', 'b', 'c' No two adjacent characters are the same 👉 Instead of generating all strings blindly, we: Build valid strings using backtracking Maintain lexicographical order naturally 🔍 Core Approach: 1️⃣ Backtracking (DFS) Start building string character by character At each step: Choose from 'a', 'b', 'c' Skip if same as previous character 2️⃣ Lexicographical Order Always try characters in order: 'a' → 'b' → 'c' 3️⃣ Stop Early Once we reach the k-th string, stop recursion 👉 If total strings < k → return "" 🔥 What I Learned Today: Backtracking is powerful for constraint-based generation Ordering decisions early helps avoid extra sorting Early stopping = major optimization 📈 Challenge Progress: Day 14/100 ✅ 2 weeks strong! LeetCode, Backtracking, Recursion, Lexicographical Order, Strings, DFS, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Backtracking #Recursion #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
Spaghetti code is easy to write. Clean code is easy to change. Structured code may feel like overkill. Interfaces, modules, patterns — why add all that ceremony for something that already works. But the longer you work with code, the more you realize that changing code is what you actually spend most of your time doing. At 200 lines, a flat script is fine. At 2,000 lines, you start feeling the friction. At 20,000 lines, without structure and boundaries, every small change becomes archaeology — digging through layers of tangled logic just to figure out what’s safe to touch. This applies whether the code is written by a developer or an AI coding agent. Clean code isn’t about making code look impressive. It’s about giving your team the confidence to change and ship, Not “Let’s push it to next release” #SoftwareDevelopment #CleanCode #Programming #CodeQuality #SoftwareEngineering #DevLife #LearnToCode #Refactoring #Python
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