🚀 Day 14 – LeetCode #13: Roman to Integer | Mastering String Parsing Today’s problem looks easy at first glance… but it exposes whether you really understand character mapping, edge cases, and sequential logic. 🔹 Problem: Convert a Roman numeral (I, V, X, L, C, D, M) into its integer value. Sounds simple — until you hit tricky cases like: IV = 4 (not 6) IX = 9 XL = 40 CM = 900 If you blindly add values, you’ll get wrong answers. You must detect when a smaller value appears before a bigger one → subtract instead of add. 💡 Core idea: Map each symbol → integer Traverse left → right If current < next → subtract Else → add This problem trains: ✅ HashMap usage ✅ String traversal ✅ Greedy thinking ✅ Edge-case handling ✅ Clean conditional logic Stop memorizing. Understand the rule. That’s what interviews test. Consistency > talent. Day 14 done. On to Day 15. #LeetCode #DSA #Java #CodingInterview #ProblemSolving #100DaysOfCode #SoftwareEngineer #Developers #TechCareer #LearningInPublic #Algorithms
More Relevant Posts
-
🚀 Day 17/30 – Fast Exponentiation & Logarithmic Thinking Today’s problem was to implement power(x, n) efficiently. A straightforward approach would multiply x repeatedly n times — but that leads to O(n) time complexity, which is not scalable for large inputs. Instead, I implemented Binary Exponentiation (Fast Power). 💡 Approach Convert n to a positive long to safely handle edge cases If n is negative → invert x Repeatedly: Multiply the result when the current bit is 1 Square the base Halve the exponent This reduces the complexity to: ⏱ O(log n) 📊 Performance ✅ All test cases passed ⚡ 0 ms runtime (100% performance) 💾 Optimized memory usage 📚 Key Takeaway This problem is a perfect example of how: Understanding number representation in binary Leads to exponential performance improvement From linear → logarithmic time just by changing the approach. Also reinforced the importance of handling edge cases like negative powers and integer limits. 🎯 Day 17 complete. Currently focusing on patterns that frequently appear in coding interviews — binary search, bit manipulation, and fast exponentiation. #Day17 #30DaysOfCode #LeetCode #Java #Algorithms #BinaryExponentiation #ProblemSolving #InterviewPreparation #SoftwareEngineering #CodingJourney #Consistency #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 13 – LeetCode 60 Days Challenge Problem Solved: 4 Sum Today I solved the classic 4Sum problem using Sorting + Two Pointer technique. 🔹 Problem: Given an array of integers, return all unique quadruplets such that: nums[i] + nums[j] + nums[left] + nums[right] == target 🔹 Approach I Used: 1️⃣ First, sort the array. 2️⃣ Fix the first element using loop (i). 3️⃣ Fix the second element using loop (j). 4️⃣ Use two pointers (left & right) for remaining two elements. 5️⃣ Carefully skip duplicates to avoid repeated quadruplets. 6️⃣ Used long for sum to avoid integer overflow. This reduces the brute force O(n^4) solution to: ⏱ Time Complexity: O(n^3) 📦 Space Complexity: O(1) (excluding result list) 🔹 Key Learning: - Two pointer technique becomes powerful after sorting. - Duplicate handling is VERY important in combination problems. - Always consider overflow when dealing with large integers. - Pattern recognition: 4Sum is an extension of 3Sum. 💡 Interview Insight: Most interviewers expect you to: ✔ First explain brute force ✔ Then optimize step by step ✔ Handle duplicates properly ✔ Think about overflow edge cases Consistency > Motivation 🔥 Day 13 Done ✅ On to Day 14 🚀 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #InterviewPreparation
To view or add a comment, sign in
-
-
🚀 DSA Daily Challenge – Day 7 🧠 Problem: Remove Element (LeetCode 27) 💡 Problem Statement: Given an integer array nums and an integer val, remove all occurrences of val in-place and return the number of remaining elements. ⚠️ You must modify the array in-place with O(1) extra space. 🔥 Intuition Brute force idea: Create a new array and copy elements ≠ val ❌ But the problem requires in-place modification. So how do we solve it efficiently? 👉 Use the Two Pointer Technique 🛠 Approach (Two Pointers – In Place) • Use one pointer i to traverse the array • Use another pointer index to track where the next valid element should go • If nums[i] != val → copy it to nums[index] • Increment index At the end, index represents the new length. ⚙️ Complexity ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 👉 Think Two Pointers + Overwriting Pattern This pattern is very common in coding interviews 🔥 #LeetCode #LeetCode27 #RemoveElement #DSA #DataStructures #Algorithms #CodingInterview #InterviewPreparation #Java #TwoPointers #ArrayProblems #InPlaceAlgorithm #TimeComplexity #BigO #CompetitiveProgramming #FAANGPrep #100DaysOfCode
To view or add a comment, sign in
-
-
📝 DSA Practice — Top K Frequent Words (LeetCode 692) Today I solved Top K Frequent Words, an interesting variation of the top-k pattern that combines frequency counting with custom ordering logic. 🔍 Key Learnings First step is building a word frequency map. Ranking is based on frequency first, then lexicographical order. Priority queues help maintain the correct top-k ordering efficiently. Custom comparator logic plays a crucial role. 🧠 Why This Problem Matters Frequently asked in coding interviews. Strengthens understanding of hash maps + heaps + custom sorting. Similar patterns appear in search engines and recommendation systems. 📌 Final Takeaway This problem shows that real-world ranking problems often involve multiple sorting conditions, and designing the right comparator makes all the difference. #leetcode #dsa #heap #hashmap #strings #customsorting #problemSolving #codingpractice #java #datastructures #interviewpreparation #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 38 | LeetCode DSA Journey – Stack & Expression Parsing 📌 Problem Solved: 224. Basic Calculator ⚙️ Difficulty: Hard ☕ Language: Java 🔥Today’s challenge was all about parsing expressions from scratch—no shortcuts, no built-in evaluators like eval() 🚫. A solid test of understanding stacks, signs, and operator precedence. 🧠 Approach Breakdown 🔹 Used a Stack to store intermediate results and signs 🔹 Handled parentheses by saving the current state before diving in 🔹 Built numbers digit by digit for multi-digit support 🔹 Applied sign management to keep calculations accurate 📊 Performance Snapshot ⏱ Runtime: 13 ms 💾 Memory: 46.50 MB (Beats 71.41%) 💡 Key Takeaways ✔ Stack is a powerful tool for expression evaluation ✔ Managing state (result + sign) is crucial with nested parentheses ✔ Clean logic > shortcuts ✔ Hard problems sharpen real-world problem-solving skills Step by step, getting more comfortable with complex parsing problems and low-level logic 🔥 On to the next challenge 💪 #Day38 #LeetCode #Java #DSA #Stack #ProblemSolving #HardProblems #SoftwareEngineering #Consistency
To view or add a comment, sign in
-
-
⚡ Day 4 — Merge Intervals (Greedy + Sorting) Consistency is slowly turning confusion into clarity. Today’s problem was Merge Intervals — a classic example where the real difficulty isn’t coding, but recognizing the pattern. 🧩 Problem solved: Merge Intervals 🔢 LeetCode: 56 At first glance, the problem looks messy because overlapping ranges create too many comparison possibilities. The turning point was realizing that trying to merge randomly is inefficient — sorting the intervals by start time simplifies everything. Once sorted, the logic becomes straightforward: • Compare the current interval with the last merged interval • If they overlap → extend the boundary • If they don’t → push a new interval No unnecessary comparisons. Just one clean pass. 🔍 Key learnings: • Sorting often converts complex interval problems into linear scans • Greedy decisions work when local choices don’t break global correctness • Tracking only the “last merged interval” avoids redundant checks • Pattern recognition matters more than code length Slowly building the instinct to see patterns before writing loops. Solutions are available here: https://lnkd.in/gW8atfqw More tomorrow. #DSA #Java #LeetCode #GreedyAlgorithm #CodingJourney #StudentDeveloper #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 15 – LeetCode 209 | Minimum Size Subarray Sum | Sliding Window Mastery Most people brute-force this problem with O(n²) nested loops and call it a day. That’s lazy thinking. If your first instinct isn’t O(n) with sliding window, you’re not thinking like a serious engineer yet. Problem: Given positive integers, find the smallest length subarray whose sum ≥ target. Naive: Check every subarray → slow → useless for large inputs. Correct mindset: Two pointers + running sum. Move right → expand window When sum ≥ target → move left → shrink window Track minimum length Time: O(n) Space: O(1) This is not just a problem — it trains: • Window optimization • Two-pointer thinking • Real interview patterns • How to kill brute force early If you still default to nested loops, fix that habit now. Top engineers think in patterns, not force. Consistency check: 15 days straight of DSA. No skips. No excuses. Code + explanation done. On to Day 16. #LeetCode #Day15 #DSA #Java #SlidingWindow #Algorithms #CodingInterview #SoftwareEngineer #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
🚀 Solved: Chocolate Distribution Problem (Greedy + Sorting) Today I solved an interesting problem based on Sorting and Sliding Window technique. 🧩 Problem Statement: Given an array where each element represents the number of chocolates in a packet, and m students, distribute exactly one packet to each student such that the difference between the maximum and minimum chocolates given is minimum. 💡 Key Insight: After sorting the array, the minimum difference will always be found among m consecutive elements. 🔎 Approach: 1️⃣ Sort the array 2️⃣ Use a sliding window of size m 3️⃣ Compute arr[i + m - 1] - arr[i] 4️⃣ Track the minimum difference ⏱ Time Complexity: O(n log n) due to sorting 🧠 What I Learned: Importance of recognizing greedy patterns How sorting simplifies range-based problems Practical use of sliding window technique Problems like these strengthen core DSA fundamentals and interview confidence 💪 #DataStructures #Algorithms #Java #CodingInterview #ProblemSolving #GreedyAlgorithm #Sorting #SlidingWindow #100DaysOfCode #DSAPractice
To view or add a comment, sign in
-
-
🚀 Today’s DSA Progress! Spent time practicing arrays and strings in LeetCode/NeetCode. Learned some key patterns that are essential for coding interviews: Longest Common Prefix – vertical scanning to find shared prefix. Group Anagrams – HashMap with sorted string or frequency count. Remove Element – in-place removal using two pointers. Majority Element – Boyer-Moore Voting Algorithm (O(n), O(1) space). Sort an Array – Merge Sort for divide-and-conquer sorting. Sort Colors – Dutch National Flag algorithm for one-pass in-place sort. Top K Frequent Elements – HashMap + Heap or Bucket Sort. 💡 Key Takeaway: Mastering two-pointers, hashing, bucket sorting, and in-place operations makes array & string problems faster and more intuitive. 📌 All the practise is uploaded on my GitHub: https://lnkd.in/dEye4D2X #DSA #LeetCode #NeetCode #Algorithms #Coding #ProblemSolving #DataStructures
To view or add a comment, sign in
-
Solved the Sort Colors problem using the three-pointer approach (Dutch National Flag algorithm). The solution sorts an array containing only 0s, 1s, and 2s in a single pass without using any extra space. By maintaining three pointers — low, mid, and high — the algorithm places 0s at the beginning, 1s in the middle, and 2s at the end through controlled swaps. Time Complexity: O(n) Space Complexity: O(1) Understanding pointer-based in-place algorithms is important for mastering array manipulation and writing clean, optimized, interview-ready code. #Java #DSA #ProblemSolving #Coding #SoftwareEngineering #LeetCode #Developers
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