46 of #100DaysOfCode 🚀 Solved a classic stack problem today: removing adjacent duplicates from a string using a clean and efficient approach. 🔍 Key Idea: Use a stack to track characters — if the current character matches the top, pop it (duplicate removed). Otherwise, push it. Simple yet powerful! 💡 Learned: Stack isn’t just a data structure, it’s a mindset for handling problems involving reversals, matching, and cancellations. ⚡ Optimized further by using a string as a stack for better performance. #LeetCode #DataStructures #Stack #CPP #CodingJourney #KeepLearning
Somesh Pandey’s Post
More Relevant Posts
-
Day 48 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Next Greater Element We were given an array. For each element, we had to find the next greater element on the right side. If none exists → return -1. Example: [4, 5, 2, 10] → [5, 10, 10, -1] 💻 Brute Force Approach 🔹️For each element, check all elements on the right. 🔹️Find the first greater element. 🔹️If found → store it. 🔹️Else → store -1. Time Complexity: O(n²) Space Complexity: O(1) Works. But slow. 💻 Optimal Approach (Using Stack) 🔹️Traverse from right to left. 🔹️Use a stack to store elements. 🔹️For each element: ▪️Pop smaller elements from stack ▪️Top of stack = next greater element ▪️If stack empty → answer is -1 🔹️Push current element into stack Efficient. Single pass. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Monotonic stack helps in nearest greater problems. ▫️Traversing from right simplifies logic. ▫️Popping smaller elements keeps stack useful. ▫️Stack stores only potential answers. Day 48 completed. Stack patterns getting stronger 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Building strong fundamentals, one step at a time! Today I worked on implementing Selection Sort using both for loop and while loop to strengthen my understanding of logic building. 📌 Example: Input: [12, 11, 14, 6, 7] → Output: [6, 7, 11, 12, 14] 🔹 What I explored: How Selection Sort works step by step using for loop and while loop 💡 It’s interesting how the same algorithm can be written in multiple ways, yet the core logic remains the same! I’ve uploaded the code on my GitHub — would love your feedback 🙌 #DataStructures #Algorithms #JavaScript#CodingPractice #LearningJourney #GitHub 😊
To view or add a comment, sign in
-
LinkedIn Draft – Remove Nth Node From End | Day 12 #DailyLeetcode -Day 12 🖥 Sometimes, the problem isn’t about moving forward… it’s about understanding what’s happening from the end. 🔄 LeetCode Day 12 was exactly that. The problem 🎯 1 → 2 → 3 → 4 → 5 Remove the nth node from the end. Example: n = 2 → remove 4 1 → 2 → 3 → 5 The approach ⚡ Instead of counting from the end… I used two pointers with a gap: Move fast ahead by n steps 🚀 Then move both slow and fast together The intuition 💡 When fast reaches the end, slow is already standing just before the node to delete 🎯 Now delete next of slow . Why this stands out - 1) No need to calculate length ❌ 2) Single traversal 🔁 3) Clean pointer logic ⚡ Complexity ⏱️ Time → O(n) Space → O(1) Reflection ✨ Some problems feel tricky… until you shift your perspective. A simple “gap” between pointers can turn a multi-step solution into a one-pass solution. #LeetCode #DailyCoding #LinkedList #RemoveNthNode #ProblemSolving #CodingJourney #100DaysOfCode #TechLearning #Algorithms #DataStructures #CodingLife
To view or add a comment, sign in
-
-
Day 49 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Remove All Adjacent Duplicates in String We were given a string s. Task was to remove all adjacent duplicates. If duplicates are removed, new duplicates may form. So we repeat until no duplicates remain. Example: "abbaca" → "ca" 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Traverse each character. 🔹️If stack is not empty and top == current character → pop 🔹️Else → push current character 🔹️At the end, build string from stack Duplicates get removed automatically. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack helps in handling adjacent comparisons. ▫️Removing elements can create new patterns. ▫️Single pass solution is possible with stack. ▫️String problems often map to stack operations. Day 49 completed. Almost at 50 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
The Day's Particulars: #Day23 of the 30 Days of Code Challenge 💠Problems Conquered: Reverse Nodes in k-Group, Swap Nodes in Pairs, Linked List Random Node, Merge In Between Linked Lists, and Merge Nodes in Between Zeros 💠Patterns Explored: Segmented Reversal, Conditional Node Merging, and Random Selection 💠Future Notes to Self: Solving a complex problem becomes significantly less intimidating when you realize it is often just a generalized version of a smaller, easier problem. Master the base case, and the complex case naturally follows! 𝐃𝐞𝐚𝐫𝐞𝐬𝐭 𝐆𝐞𝐧𝐭𝐥𝐞 𝐑𝐞𝐚𝐝𝐞𝐫𝐬, Day 23 was an absolute marathon! I managed to knock out five distinct Linked List problems today, heavily focusing on segmented pointer manipulation. The highlight of the day was tackling 𝘚𝘸𝘢𝘱 𝘕𝘰𝘥𝘦𝘴 𝘪𝘯 𝘗𝘢𝘪𝘳𝘴 alongside my second Hard problem: 𝘙𝘦𝘷𝘦𝘳𝘴𝘦 𝘕𝘰𝘥𝘦𝘴 𝘪𝘯 𝘬-𝘎𝘳𝘰𝘶𝘱. I quickly realized that swapping nodes in pairs is essentially just reversing nodes in a k-group where k = 2. By writing a solid helper function to reverse a specific segment of a list, I could cleanly apply the exact same underlying logic to solve both problems. It was a great lesson in how complex problems are just simpler problems scaled up. I also worked through 𝘔𝘦𝘳𝘨𝘦 𝘐𝘯 𝘉𝘦𝘵𝘸𝘦𝘦𝘯 𝘓𝘪𝘯𝘬𝘦𝘥 𝘓𝘪𝘴𝘵𝘴 and 𝘔𝘦𝘳𝘨𝘦 𝘕𝘰𝘥𝘦𝘴 𝘪𝘯 𝘉𝘦𝘵𝘸𝘦𝘦𝘯 𝘡𝘦𝘳𝘰𝘴. Both were fantastic exercises in conditional pointer reassignment, carefully traversing to specific boundaries (either indices or specific node values like zero) and cleanly snipping out or replacing entire chunks of the list without losing the rest of the chain. Finally, 𝘓𝘪𝘯𝘬𝘦𝘥 𝘓𝘪𝘴𝘵 𝘙𝘢𝘯𝘥𝘰𝘮 𝘕𝘰𝘥𝘦. offered a completely different flavor. It required fetching a random node with equal probability, which shifts the focus away from pure structural manipulation and into mathematical probability and data retrieval. The momentum is real, and the pointer logic is feeling like second nature now. On to Day 24! Yours in code, Saumya #LeetCode #30DaysOfCode #JavaDeveloper #BackendDeveloper #DataStructures #Algorithms #ProblemSolving #TechJourney #LinkedLists #TwoPointers #PointerManipulation #SoftwareEngineering #TechCommunity #DailyCoding #GrowthMindset #dsaStories
To view or add a comment, sign in
-
-
Day 58 of solving LeetCode problems. Today’s focus: Range Sum Query – Mutable At first glance, it looks simple. But the moment updates enter the picture, brute force collapses. This problem pushes you toward Segment Trees / Fenwick Trees — where preprocessing and smart updates turn inefficiency into precision. Key takeaway: Speed isn’t about doing things faster. It’s about avoiding unnecessary work entirely. Still consistent. Still refining. There’s always a structure behind the surface. 3 → 6 → 9 #LeetCode #Algorithms #DataStructures #CodingJourney #DSA #SegmentTree #FenwickTree #ProblemSolving #SoftwareEngineering #Consistency #KeepBuilding #DeveloperMindset
To view or add a comment, sign in
-
-
Small feature, BIG learning 👇 Implemented: 📸 Multiple Image Upload 📦 Stored as JSON in database 🖼️ Rendered in grid + table view Sounds easy? Wait till you handle: File validation Storage linking Frontend rendering Edge cases 😅 This is where real dev growth happens. #FullStack #LaravelDev #ReactDev #BuildInPublic #CodingLife #DevGrowth
To view or add a comment, sign in
-
Solved “Letter Combinations of a Phone Number” on LeetCode 💡 What looks simple on the surface is actually a clean exercise in recursion + backtracking. 🔍 Key takeaways: - Mapping digits to characters is straightforward, but generating all combinations efficiently is where the thinking comes in - Backtracking helps explore all possibilities while keeping the solution clean and scalable - Important to control recursion depth and maintain state (temp) correctly 💭 What I focused on: - Building combinations incrementally - Reverting state after each recursive call (classic backtracking pattern) - Keeping the solution readable and modular This problem reinforced how powerful recursion is when combined with proper state management. On to the next one 🚀 #DSA #LeetCode #Backtracking #Recursion #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 15 of my 100-Day LeetCode Challenge: Streamlining Data Streams! 🌊 Today I tackled LeetCode #2149: Rearrange Array Elements by Sign. The problem asks you to take an array of positive and negative numbers and interleave them perfectly (positive, negative, positive...) while strictly maintaining their original relative order. The Engineering Solution: The Two-Pointer Placement Technique. While you could split the data into two separate lists and merge them, that requires multiple passes. To do this efficiently, I used a single-pass approach: • Initialize an exact-size result array. • Use two separate index trackers: 'positive' starting at 0, and 'negative' starting at 1. • Iterate through the raw data once. If a number is positive, place it at positive and jump the pointer forward by 2. If negative, place it at negative and jump by 2. The Complexity Win: ⏱️ Time: O(N) - The raw data is evaluated in exactly one pass. 💾 Space: O(N) - We allocate exactly what is needed for the restructured output. Often, engineers get hyper-focused on trying to achieve O(1) space. But trying to solve this specific problem in-place while preserving relative order requires heavy element shifting, resulting in a massive O(N^2) time penalty. Understanding when to trade space for speed is the core of system design! #100DaysOfCode #Java #LeetCode #DataStructures #Algorithms #SeniorEngineer #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
What the duck! 🦆 Rubber Duck in GitHub Copilot CLI = your second-opinion reviewer. It pairs a complementary model (GPT-5.4) with orchestrated reasoning to: • Catch architectural issues • Spot cross-file conflicts • Surface subtle bugs → Especially powerful on messy, multi-file tasks where a single model struggles. 🦆 Now in experimental mode for devs who want an extra set of eyes on plans, code, and tests. https://lnkd.in/dewQuaeJ Curious—would you trust a “second model” to review your code? #GitHub #AI #Copilot #DeveloperTools #DevEx #MachineLearning
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