Continuing my DSA journey, * Problem: Number of Atoms (726) * Approach: -I solved this using a stack-based parsing approach. -I used a stack of maps to keep track of atom counts at different levels. While iterating through the string: -On '(' → push a new map onto the stack -On ')' → pop the top map, multiply counts, and merge back -For elements → parse the name and count, then update the current map * Key Insight: -The tricky part was handling nested parentheses and applying multipliers correctly. -Using a stack helps manage different scopes efficiently. * What I Learned: This problem improved my understanding of string parsing with stacks. #LeetCode #DSA #Java #Stack #Strings #ProblemSolving
Stack-Based Parsing for Number of Atoms Problem
More Relevant Posts
-
🚀 Day 73 of #100DaysOfLeetCode with edSlash Today’s problem: Next Greater Node in Linked List (LeetCode 1019) 🔍 What I learned: How to find the next greater element in a linked list Converting a linked list into an array for easier processing Using a monotonic stack to solve problems efficiently 💡 Key Insight: Instead of brute force (O(n²)), using a stack helps reduce time complexity to O(n) by keeping track of elements in decreasing order. ⚡ Approach: Convert linked list → array Use stack to track indices Find next greater elements 📈 Complexity: Time: O(n) Space: O(n) Every day = 1% better 💪 Let’s keep pushing 🚀 #Day73 #LeetCode #DSA #LinkedList #Stack #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 80/90 Solved: Largest Rectangle in Histogram Core idea: → Use monotonic stack to find nearest smaller to left & right → Width = (right - left - 1), maximize area This is one of those problems where the pattern isn’t obvious at first. Once the left/right boundary logic clicks, the solution becomes systematic. #Consistency #DSA #LeetCode #Stack #MonotonicStack #ProblemSolving #Java #Algorithms
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟔 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding a peak element using binary search. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Find Peak Element 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Used binary search instead of linear scan • Compared the middle element with its next element Logic: • If nums[mid] > nums[mid + 1] → peak lies on the left side (including mid) • Else → peak lies on the right side • Continued until left == right 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Binary search can be applied on patterns, not just sorted arrays • A peak always exists due to problem constraints • Comparing adjacent elements helps determine direction • Reducing the search space is the key idea 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(log n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Binary search is not about sorted arrays — it’s about eliminating half of the search space using logic. 56 days consistent 🚀 On to Day 57. #DSA #Arrays #BinarySearch #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
🔥 Today’s DSA Update— #Day58 #MonotonicStack Today I worked on finding Next Greater Element I (Leetcode 496). 💡 What I understood This pattern is useful for problems where we need to find things like: 1. Next greater element 2. Next smaller element Instead of using nested loops (which take O(n²)), we can solve it in O(n) using a stack. 💡 The key idea We use a stack to keep elements that are still “waiting” for their answer. When we find a bigger element: 1. We pop all smaller elements from the stack 2. For each popped element, we now know its next greater value 3. Each element is pushed and popped only once. 🧠 What I learned today Today’s lesson was that stacks are not just for push and pop operations — they can be used to store state while processing elements. This pattern feels different from normal array traversal because we are managing a “waiting list” of elements. #Java #DSA #Stack #DataStructures #LeetCode #ConsistencyCurve
To view or add a comment, sign in
-
-
Day 72 of #100DaysOfCode Problem: Convert Sorted Array to Height-Balanced BST Today I learned how to efficiently convert a sorted array into a balanced Binary Search Tree using Divide & Conquer. Key Insight: Pick the middle element as the root to maintain balance. Recursively build: Left subtree from left half Right subtree from right half This ensures: Optimal height Faster search operations ⏱ Time Complexity: O(n) 📦 Space Complexity: O(log n) Consistency is the real game changer #DSA #Java #BinaryTree #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 35 of Consistency 💻🔥 Solved Longest Substring Without Repeating Characters — a classic sliding window problem that really tests optimization skills. ✨ Key Takeaways: Mastered the sliding window technique Used HashMap for efficient lookup Improved understanding of two-pointer approach ⚡ Performance: Runtime: 5 ms Beat: 87%+ submissions Every day is about getting sharper, not just solving problems. #LeetCode #DataStructures #Algorithms #CodingJourney #Consistency #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode – Unique Binary Search Trees II Today’s problem was all about generating all structurally unique BSTs for values from 1 to n. At first glance, it feels tricky because it's not just counting trees — we actually need to build every possible tree structure. 💡 Key Insight: Pick each number i as the root Recursively build: Left subtree from [1 ... i-1] Right subtree from [i+1 ... n] Combine every left & right subtree pair 🌳 This is a classic Recursion + Backtracking problem and is closely related to Catalan Numbers. 📌 Example: For n = 3, we get 5 unique BSTs ⚡ What I learned today: How recursion can generate combinations of structures Importance of base case (start > end → null) Combining subproblems effectively 💻 Time Complexity: Approximately O(4ⁿ / √n) Consistency is key — 90 days strong and still going 💪 Next target: 💯 #DSA #Java #LeetCode #Recursion #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 27 Today’s focus: Binary Search on modified arrays. Problem solved: • Search in Rotated Sorted Array (LeetCode 33) Concepts used: • Binary Search • Identifying sorted halves • Conditional search space reduction Key takeaway: This problem extends binary search to a rotated sorted array, where the array is not fully sorted but divided into two sorted parts. At each step, we: • Find the mid element • Check which half (left or right) is sorted • Decide whether the target lies in the sorted half • Eliminate the other half This allows us to still achieve O(log n) time complexity. Continuing to strengthen fundamentals and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 48 🔍 Solved: Find Peak Element Today I worked on an interesting Binary Search problem where the goal was to find a peak element in an array. 💡Key Insight: By comparing the middle element with its next element, we can determine the direction of the peak. 📌 Approach: ✔ Applied Binary Search for O(log n) efficiency ✔ Compared mid with next element ✔ Moved towards the increasing side to find peak ✔ Reduced search space step by step Why this works: Since adjacent elements are not equal, there will always be at least one peak. By comparing neighboring elements, we can decide the direction and reduce the search space efficiently. 🎯 What I Learned: This problem showed how Binary Search can be used beyond searching—especially for identifying patterns like peaks in arrays. #Java #DSA #LeetCode #BinarySearch #CodingJourney #ProblemSolving #TechSkills 🚀
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 47 🔍 Solved: Find Minimum in Rotated Sorted Array Today I explored another interesting variation of Binary Search. Instead of searching for a target, the goal was to find the minimum element in a rotated sorted array. 💡 Key Insight: By comparing the middle element with the last element, we can determine which half contains the minimum value. Approach: ✔ Used Binary Search to achieve O(log n) time complexity ✔ Compared mid with end to identify the unsorted portion ✔ Narrowed down the search space efficiently What I Learned: This problem helped me understand how binary search can be applied beyond simple searching—especially in rotated and partially sorted arrays. #Java #DSA #LeetCode #BinarySearch #CodingJourney #ProblemSolving #TechSkills
To view or add a comment, sign in
-
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