DevLog Day 46 Today I finally conquered a problem that had beaten me before. Redemption days hit different. The problem was Sort Colors on LeetCode, a medium level question where you are given an array containing only 0s, 1s, and 2s representing colors, and you need to sort it in place in a single pass. No built in sort, no multiple iterations. The brute force is straightforward, you could use a built in sort function or classic algorithms like bubble sort or insertion sort, but the single pass constraint rules all of that out. My solution used counting sort. Since we only ever have three possible values, I used a fixed size array to count the frequency of 0s, 1s, and 2s, then overwrote the original array using those counts. Because the frequency array never grows beyond 3 elements regardless of input size, the space stays constant. There is something satisfying about coming back to a problem that once stumped you and seeing it clearly this time. It is proof that the reps are adding up even when it does not feel like it in the moment. #100DaysOfCode #LeetCode #NeetCode #DataStructures #Arrays #CodingJourney #ProblemSolving #Programming #SoftwareEngineering #Tech
Conquering Sort Colors on LeetCode with Counting Sort
More Relevant Posts
-
DevLog Day 45 Today was a revisit day. Sometimes you need to go back to the basics and there is nothing wrong with that. The problem was Remove Element. You are given an array and a value, and you need to remove all occurrences of that value in place and return the length of the resulting array. No extra space, just you and the array. It is one of those problems that looks almost too simple on the surface but it is a great exercise in thinking about in place operations and pointer manipulation. Going back to a problem you have already seen hits differently the second time around because you start noticing the patterns you missed before and connecting them to harder problems you have solved since. #100DaysOfCode #LeetCode #NeetCode #DataStructures #Arrays #CodingJourney #ProblemSolving #Programming #SoftwareEngineering #Tech
To view or add a comment, sign in
-
DevLog Day 44 Today I solved one of the trickiest problems I have come across so far. My brain is still hurting but here we are. The problem was Permutation in String. You are given two strings s1 and s2 and you need to check if any permutation of s1 exists as a substring inside s2. Simple to read, painful to solve. I worked through both a brute force and an optimized approach. The brute force sorts every window of s2 and compares it against the sorted s1, which works but costs O(n²) time. The optimized approach swaps sorting for a hashmap that tracks letter frequencies across a sliding window, which is faster in practice but honestly just as tricky to wrap your head around when you are seeing it for the first time. The best solution goes even further with a pure sliding window that avoids nested loops entirely. I will be honest, I do not fully understand the logic behind it yet and I know I will need to revisit this one a few times. But that is fine. Some problems are not meant to click on the first try and I know this one will teach me something deeper about sliding windows once it does. #100DaysOfCode #LeetCode #NeetCode #DataStructures #SlidingWindow #CodingJourney #ProblemSolving #Programming #SoftwareEngineering #Tech
To view or add a comment, sign in
-
Day 56 of solving LeetCode. Today’s problem: Count Primes Result: Accepted ✔️ (66/66 test cases) Performance: • Runtime: 96 ms (beats 75.25%) • Memory: 51.26 MB Key takeaway: Brute force thinking doesn’t scale. The real shift is recognizing patterns like the Sieve of Eratosthenes — precompute smartly instead of checking repeatedly. Most people stay stuck trying to optimize loops. The smarter move is changing the approach entirely. Consistency > motivation. 56 days in. No breaks. No excuses. ∆ #LeetCode #CodingJourney #DSA #Programming #ProblemSolving #100DaysOfCode #DeveloperLife #CodingDaily #Algorithms #Consistency #GrowthMindset
To view or add a comment, sign in
-
-
Solved LeetCode Find the Difference in Rust using a clean XOR approach. A great example of solving string problems efficiently with O(n) time and O(1) space. 🎥 Watch here: https://lnkd.in/d4YFWAPH #Rust #LeetCode #Programming #Algorithms
Find the Difference | LeetCode | Rust | 🦀
https://www.youtube.com/
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
-
-
Understanding the path to the solution. I recently solved LeetCode 62: Unique Paths. While the problem seems simple at first glance, it’s a perfect example of how Dynamic Programming can optimize a solution from exponential time to linear time. The core idea: The number of ways to reach any cell is simply the sum of ways to reach the cell above it and the cell to its left. Seeing that "Accepted" screen with a 0ms runtime is always a great feeling! #SoftwareEngineering #DynamicProgramming #Coding #LeetCodeDaily
To view or add a comment, sign in
-
-
Binary tree right side view Approach: - Keep a level variable - If level == result.size(), add current node (first node of that level) - Traverse right first, then left Time: O(n) Space: O(h) (worst: O(n), best: O(log n)) #Algorithms #DSA #LeetCode #coding #Programming
To view or add a comment, sign in
-
-
Before Stack Overflow, debugging meant reading 800-page MSDN documentation or waiting 2 days for the one senior dev who might know the answer. After Stack Overflow: copy the error, paste into Google, first result has the exact answer from 2009. Stack Overflow didn't just answer questions. It democratized programming knowledge for the entire world. 👇 What's the oldest Stack Overflow answer that saved your life? Drop the year! 😂 #stackoverflow #programming #softwaredeveloper #nostalgia #coding
To view or add a comment, sign in
-
-
Day 70 of #100DaysOfCode 💻 Solved LeetCode 523 – Continuous Subarray Sum using an optimized Prefix Sum + HashMap approach. 💡 Key Insight: If two prefix sums have the same remainder when divided by k, the subarray between them is divisible by k. ⚡ Reduced time complexity from O(n²) → O(n) #leetcode #coding #dsa #cpp #programming #placements
To view or add a comment, sign in
-
-
Writing fast, reliable software sometimes means solving problems that have no obvious answer. Our R&D team just published a #TechTalk article documenting one of those problems: how do you make #Cython classes that are created automatically at runtime carry the right data with them, without slowing things down? The article walks through every approach they tried, why some fell short, and the solution they landed on. It also covers a subtle crash bug hiding in the final design, and how to handle it safely. 🔗 Read it here: https://lnkd.in/en4mP4cM #SoftwareEngineering #Programming
To view or add a comment, sign in
-
More from this author
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