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
Solving Permutation in String Problem with Brute Force and Optimized Approaches
More Relevant Posts
-
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
To view or add a comment, sign in
-
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
-
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
-
-
🚀 Day 7 of My LeetCode Journey Today’s problem: Reverse Integer At first glance, it looks simple — just reverse digits. But the real challenge was handling 32-bit integer overflow without using 64-bit storage. 🔍 What I learned: How to extract digits using modulo (%) Building the reversed number step by step Most importantly, checking overflow before updating the result ⚠️ Edge Case: If the reversed number goes beyond the 32-bit range [-2³¹, 2³¹ - 1], we must return 0 💡 Example: Input: 123 → Output: 321 Input: -123 → Output: -321 Input: 1534236469 → Output: 0 (Overflow case) Consistency over perfection 💪 #Day7 #LeetCode #DSA #CProgramming #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Every great programmer starts with the basics. Diving deep into Singly Linked Lists — understanding how nodes connect, how memory is managed dynamically, and how operations like insertion and deletion actually work behind the scenes. It’s not just about code, it’s about building logic. awareness of hardware-level behavior like cache alignment and data locality. #Multithreading #Concurrency #Programming #SoftwareEngineering #BackendDevelopment #CPP #CppProgramming #ModernCPP #Multithreading #Concurrency #ParallelProgramming #STL #SystemProgramming #SoftwareEngineering #CodingLife #DSA #Coding #LinkedList #TechLearning #ProgrammerMindset
To view or add a comment, sign in
-
-
Ever look at a LeetCode problem and think, "Oh, this is just simple math," only to see a constraint of $10^{15}$ staring back at you? That was my experience with the "Count Good Numbers" problem today. The core logic was actually pretty straightforward: even indices get even digits (5 options), and odd indices get prime digits (4 options). But trying to calculate 5^even * 4^odd for massive numbers? Immediate Time Limit Exceeded (TLE). I had to scrap the standard approach and write a custom pow() function using Binary Exponentiation. It’s wild how applying modulo 10^9 + 7 at every single multiplication step within the recursive call is the exact difference between a failing solution and a clean O(log n) pass without integer overflow. Definitely a great reminder that knowing the brute-force math is only half the battle—optimizing it is where the real engineering happens. Back to the grind! #LeetCode #DSA #CPP #CompetitiveProgramming #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
Ever faced a memory leak… in code or in life? 😂 Post: In C, forgetting to free() memory leads to leaks. In life, forgetting to “let go” does the same. 🔹 Deleted the node 🔹 But memory still occupied That’s not just a bug… that’s emotional engineering 😄 👉 Lesson: Always clean up your pointers (and your past) #CProgramming #LinkedList #MemoryLeak #CodingHumor #SoftwareEngineering #EmbeddedSystems #DebuggingLife #TechMemes #ProgrammerLife
To view or add a comment, sign in
-
-
Stop memorizing Rust rules. Start deriving them. 🦀 This free interactive course reframes the borrow checker not as a set of rules to memorize, but as the logical outcome of three primitives: Space, Time, and Coordinates. 📐 Every memory bug is just a failure in one of these three dimensions: 🔸 Use-after-free 🔸 Dangling pointer 🔸 Data race 🔍 Understand the framework, and the compiler's behavior clicks into place. ✅ 💡 Highly recommended for experienced devs, especially those with a C/C++ background. 👇 https://lnkd.in/gAsQvjhv #Rust #RustLang #Programming #SystemsProgramming #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Testing your C fundamentals! Can you predict the output of this nested loop? for(int i = 1; i <= 3; i++) { for(int j = 1; j <= 2; j++) { printf("%d%d ", i, j); } } Drop your answer in the comments 👇 #CProgramming #EmbeddedSystems #CodingChallenge #Loops #LearningInPublic
To view or add a comment, sign in
-
LCA - Lowest Common Ancestor of binary tree Approach: If current node is null, return null If current node is p or q, return current node Recursively search left and right If both sides return non-null → current node is LCA Otherwise → return the non-null side TC = O(n) SC = O(h) - depends on tree height (recursion stack) O(logn) - balanced tree O(n) - skewed tree #dsa #leetcode #consistency #coding #programming
To view or add a comment, sign in
-
More from this author
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