✅ Just solved LeetCode 27 — Remove Element! Small problem. Big lesson. 🧠 The task: remove all occurrences of a value from an array in-place and return the count of remaining elements. No extra array. No shortcuts. Just pointer logic. Here's the two-pointer approach I used: def removeElement(nums, val): k = 0 for i in range(len(nums)): if nums[i] != val: nums[k] = nums[i] k += 1 return k 🔍 The insight: → One pointer (i) scans every element → Another pointer (k) tracks valid write position → Overwrite only what doesn't match val → Result? O(n) time, O(1) space ✨ What's your go-to pattern for in-place array problems? Drop it below 👇 #DSA #LeetCode #CodingInterview #Programming #TwoPointers #Python #SoftwareEngineering #100DaysOfCode
Remove Element from Array in Place with Two Pointers
More Relevant Posts
-
LeetCode Day 13 – Container With Most Water Today I solved the classic “Container With Most Water” problem — a great example of optimizing from brute force to an efficient solution! Problem Insight: We are given an array of heights, and we need to find two lines that together with the x-axis form a container that holds the maximum water. Approaches: Brute Force (O(n²)) Check all possible pairs Calculate area = width × min(height[i], height[j]) Keep track of maximum Optimal Approach – Two Pointer (O(n)) Start with two pointers at both ends Calculate area Move the pointer with smaller height inward Repeat until pointers meet Key Idea: The limiting factor is always the smaller height Moving the larger height won’t help increase area Complexity: Time: O(n) Space: O(1) What I learned: How two-pointer technique drastically reduces complexity Importance of understanding constraints before coding #LeetCode #Day13 #DSA #CodingJourney #Python #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 79 of #100DaysOfCode 💡 LeetCode 338 – Counting Bits Solved today’s problem with a clean and efficient Dynamic Programming + Bit Manipulation approach 💪 🔍 Problem: For a given number "n", return an array where each index "i" contains the number of 1’s in the binary form of "i". ⚡ My Approach: Instead of recalculating bits every time, I reused previous results: 👉 "ans[i] = ans[i >> 1] + (i & 1)" 🧠 Why this works: - "i >> 1" → removes the last bit - "(i & 1)" → checks if last bit is 1 📈 Performance: ✅ Runtime: 3 ms (Beats 95% 🚀) ✅ Memory: 20.14 MB 🔥 Key Learning: Patterns in binary operations can simplify problems drastically. DP + bit tricks = powerful combo ⚡ #Day79 #LeetCode #CodingJourney #Python #DSA #DynamicProgramming #BitManipulation #100DaysOfCode
To view or add a comment, sign in
-
-
Stop guessing what happened in your code. I’m excited to share that I’ve just published lognote to PyPI! Testing and debugging production-grade Python applications often feels like searching for a needle in a haystack. I built lognote to act as a "Black Box Flight Recorder" for your code. With a simple @trace decorator, you get instant observability into function execution, arguments, and errors without the manual boilerplate. Why use lognote? Instant Observability: Log function flows with zero friction. Clean Code: Keep your logic separated from your diagnostic code. Production Ready: Built for developers who need to move fast and fix things faster. Check it out now: pip install lognote I’d love for you to try it out, star the repo, or share your feedback! #Python #OpenSource #SoftwareEngineering #PyPI #Coding
To view or add a comment, sign in
-
-
Just created my new tool and named it "ZIGBACK" for obvious reasons. It's a small red-team style experiment: dynamically generating a Zig-based reverse shell via Python and compiling it in real time. Chose Zig specifically for its low-level control, minimal runtime footprint, and ability to produce lean, dependency-free binaries ,which makes it very useful when you want to precisely understand how detection engines react to specific behaviors. Tested it against default Windows Defender to observe detection behavior. With careful API usage and structure, it remained Undetected , highlighting how much detection still depends on patterns rather than intent. Currently it is the first release, will be updating with a few more features. More to come!! 🤖 #redteaming #redteamtool #defenderbypass
To view or add a comment, sign in
-
🚀 Day 60 of #DSAJourney — Pascal’s Triangle II Today’s problem: Pascal’s Triangle II 📌 Given an integer rowIndex, return the rowIndex-th row of Pascal’s Triangle. 💡 Key Insight: Instead of generating the whole triangle, we can build the row in-place using the relation: 👉 Each element = sum of two elements from previous row 👉 Update from right to left to avoid overwriting values 🧠 Approach: Start with [1] Iteratively build each row Update elements backward to maintain correctness ⚡ Complexity: Time: O(n²) Space: O(n) (optimized, no extra triangle) 📈 What I Learned: In-place updates can optimize space significantly Backward traversal is key in many DP problems Simple math patterns → powerful solutions #Day60 #LeetCode #DSA #CodingJourney #Python #Programming
To view or add a comment, sign in
-
Want to measure pA current? Use a Source Measurement Unit (SMU). Either buy proprietary software or write the software yourself? I just put up my first open-source project for SMUs in Python that supports the following devices. You might have to install the corresponding driver for communication (especially GPIB). If you find this useful, please consider helping me cover the costs for ClaudeCode. :) #SMU #python #Keithley #Keysight #StateMachine Github: https://lnkd.in/gZPNBm6n
To view or add a comment, sign in
-
-
Happy to share 🛠️ my_mlir_track#6 Structured Control Flow (SCF) - for (Repo link: https://lnkd.in/gPE4Mrmk)! ✅ Induction Variables & Bounds: How to manage index types for loop control. ✅ Loop-Carried Variables: Using iter_args and scf.yield to maintain state across iterations. ✅ Python Integration: Compiling the logic into a shared library to bridge the gap between high-level orchestration and hardware-level execution. By utilizing this pipeline, we can generate highly optimized logic that remains easily accessible via a clean Python interface. (NOTE)Since I’ll be moving toward an assembly-like style in the next stage, I'm concluding the SCF series with this brief for loop entry. The next post will also be short; as the code becomes less "human-readable," keeping the content minimal should make it easier to digest. #LearningInPublic #Compiler #MLIR #SCF #for #C++ #HighPerformanceComputing
To view or add a comment, sign in
-
-
Claude Code is 512K lines. If you want to learn how an agent harness works, don’t start there. Start with OpenHarness, just open-sourced by HKU. 11K lines of Python, 44x lighter. It strips away telemetry, OAuth, and heavy UI, but keeps what actually matters: tool use, skills, memory, permissions, hooks, multi-agent coordination. This isn’t another agent product. It’s a white-box system that exposes the core infrastructure. The model thinks. The harness gives it hands, eyes, memory, and safety boundaries. Read it. Modify it. Build on top of it. 512K-line industrial black box vs 11K-line readable white box. Which one are you opening first? Project link in next post
To view or add a comment, sign in
-
-
🚀 Mastering the art of loops! 🔄 Discover how loops help your code execute repetitive tasks efficiently. Essentially, loops are like a magical chant that tells your program to keep doing something until a certain condition is met. For developers, mastering loops is crucial for automating tasks and iterating over data structures with ease. Here's the breakdown: 1️⃣ Initialize a counter variable 2️⃣ Set the condition for the loop 3️⃣ Define the action to perform in each iteration Sample code using a "for" loop in Python: ``` for i in range(5): print("Hello, World!") ``` 🌟 Pro Tip: Use loops to reduce redundancy in your code and boost efficiency. 💡 ⚠️ Common Mistake: Forgetting to update the counter variable in the loop, leading to an infinite loop! 🔄 🌟 What's your favorite use case for loops in your projects? Let's discuss! 💬 #Coding101 #LearnToCode #TechTips #CodeNewbie #PythonProgramming #DeveloperCommunity #LoopLogic #CodeEfficiency #ProDevSkills 🌐 View my full portfolio and more dev resources at tharindunipun.lk
To view or add a comment, sign in
-
-
If you’ve ever wondered what really happens behind: pip install I broke it down here: https://lnkd.in/gtCmxDg6 What looks like a simple command is actually a pipeline: • Your project is built into distribution artifacts • Those artifacts are published to sources like PyPI • The installer resolves dependencies and selects versions • It prefers wheels for faster installs • Falls back to building from source when needed • Finally installs everything into site-packages The key shift: - You are not installing source code. - You are installing a built artifact. This is why you’ll notice: • Some installs are instant • Some take significantly longer • Some fail due to build or environment issues #Python #PythonPackaging #PyPI #SoftwareEngineering #DeveloperTools #Programming #BuildSystems #DevTools #OpenSource
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