Day 64 of #100DaysOfCode was a battle with a single, very challenging problem: "Maximum Frequency of an Element." This one really put my skills to the test. The problem seems simple on the surface, but the optimal solution is a beautiful combination of several different patterns: 1. Frequency Counting to group identical numbers. 2. Prefix Sums to instantly calculate the "cost" of making all elements in a subarray equal. 3. Sliding Window to efficiently find the largest possible subarray that meets the cost constraint. It took a lot of time and debugging to handle all the edge cases and get the logic just right. It's one of those problems where each part is a puzzle, and you have to put them all together in the right order. Today's lesson: The most challenging problems are often the most rewarding. They force you to look beyond a single algorithm and instead compose a solution from multiple techniques in your toolkit. It's just past midnight, but solving this one was a huge confidence boost! #100DaysOfCode #Day64 #DataStructures #Algorithms #LeetCode #ProblemSolving #SlidingWindow #PrefixSum #SoftwareEngineering #Cpp
Overcoming a tough coding challenge with #100DaysOfCode
More Relevant Posts
-
💡 Day 78 of #100DaysOfCode 💡 🔹 Problem: Find Closest Number to Zero – LeetCode ✨ Approach: Traversed through the array while keeping track of the number closest to zero using absolute difference comparison. Handled ties by preferring the positive number — because even in code, positivity wins 😉 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — single pass through the array 💾 Space Complexity: O(1) — no extra space used ✅ Runtime: 3 ms (Beats 44.80%) ✅ Memory: 46.87 MB 🔑 Key Insight: Even the smallest differences matter — especially when you’re finding what’s closest to zero! ⚡ #LeetCode #100DaysOfCode #DSA #ProblemSolving #CodingChallenge #JavaProgramming #AlgorithmDesign #CodeJourney #StayPositive
To view or add a comment, sign in
-
-
🔢 Day 69 of #100DaysOfCode 🔢 🔹 Problem: Maximum Count of Positive and Negative Integers – LeetCode ✨ Approach: A simple yet powerful one-pass solution! Iterated through the array, counting positives and negatives separately — and returned whichever count was greater. Clean, direct, and efficient. ⚡ 📊 Complexity Analysis: Time Complexity: O(n) — single traversal of the array Space Complexity: O(1) — no extra data structures used ✅ Runtime: 1 ms (Beats 12.27%) ✅ Memory: 46.89 MB 🔑 Key Insight: Sometimes, simplicity wins — clarity in logic often outperforms complex tricks. Counting right leads to coding right! 💡 #LeetCode #100DaysOfCode #ProblemSolving #DSA #Array #AlgorithmDesign #LogicBuilding #CodeJourney #ProgrammingChallenge #CodingDaily #Efficiency
To view or add a comment, sign in
-
-
💻 #2DayOf150 — Remove Duplicates from Sorted Array II (LeetCode #80) Day 2 and still going strong 💪 Today was all about keeping things clean and minimal — both in code and logic. After a solid dry run session, the entire idea just clicked. The two-pointer trick felt like magic once I saw how it limits duplicates perfectly in place ✨ 🧩 Approach Use one pointer to place valid elements Allow only up to 2 occurrences of each number In one pass, the array gets compressed beautifully ✅ Time: O(n) ✅ Space: O(1) ✅ Elegant, minimal, and efficient Dry run tested. Logic locked. Consistency on track 🔥 #DSA #LeetCode #CodingJourney #ProblemSolving #Cplusplus #100DaysOfCode #2DayOf150
To view or add a comment, sign in
-
-
🚀 Day 110 of #LeetCode Challenge! Problem: Duplicate Zeros 💡 My Approach: The task is to duplicate every zero in the array in-place, shifting the remaining elements to the right. First, count the total number of zeros to determine the “virtual” extended array size. Then, use two pointers — one (i) for the original array and another (j) for the extended index. Traverse backward: Copy each element from i to j. If it’s a zero, write an additional zero (when within bounds). This avoids overwriting elements and keeps the solution in O(1) extra space. ✨ Example: Input: [1,0,2,3,0,4,5,0] Output: [1,0,0,2,3,0,0,4] ⏱ Time Complexity: O(N) — single pass from the end 💾 Space Complexity: O(1) — done in-place without extra memory 👨💻 GitHub Link: https://lnkd.in/gCuFGw-c #LeetCode #Array #InPlaceAlgorithm #TwoPointers #ProblemSolving #DuplicateZeros #Day110 #DSA #CodingChallenge #C++
To view or add a comment, sign in
-
-
Day 52 of #100DaysOfCode 🧩 Problem: 3321. Find X-Sum of All K-Long Subarrays II Difficulty: Hard This version builds on the easier “Find X-Sum” problem, but the constraints are massive — meaning brute force dies instantly. The goal is to maintain the sum of top x most frequent elements for every subarray of size k, with efficient updates as the window slides. 💡 What I learned: Balancing efficiency and correctness in sliding window problems is tricky. Frequency tracking with ordered structures (like multiset or heap) keeps updates O(log n). Rebalancing the “top x” elements correctly after each update is crucial to avoid stale counts. 🧠 Key takeaway: Optimization isn’t about shaving milliseconds; it’s about understanding how to reuse work instead of starting over every time. Every “Hard” problem eventually boils down to patience, debugging, and a little bit of emotional damage. #LeetCode #C++ #DSA #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge Complete! Just solved "Increment Submatrices by One" - a perfect demonstration of the difference array technique for efficient range updates! 💡 Solution Approach: ✅ Phase 1 - Mark boundaries: For each query, add +1 at start column, -1 after end column ✅ Phase 2 - Prefix sum: Accumulate row-wise to get final values ✅ Optimization: Instead of updating entire submatrix, just mark endpoints! The key insight: This is the classic difference array pattern! Instead of incrementing every cell in a range, we mark the boundaries: - Add +1 at the start of the range - Add -1 just after the end of the range - Then do prefix sum to "materialize" the actual values Why it works: Without optimization: Update every cell in [c1, c2] for rows [r1, r2] → O(rows × cols) per query With difference array: Mark 2 positions per row → O(rows) per query Final prefix sum: O(n²) once at the end Example: Range [1,2] in row 0 - Before prefix: [0, +1, 0, -1, 0] - After prefix: [0, 1, 1, 0, 0] ✓ Time: O(q×n×n) → O(q×n + n²) | Space: O(n²) #LeetCode #DifferenceArray #CPlusPlus #Algorithms #SoftwareEngineering #ProblemSolving #RangeUpdate #Optimization
To view or add a comment, sign in
-
-
💡 Day 77 of #100DaysOfCode 💡 🔹 Problem: Majority Element – LeetCode ✨ Approach: Used a sorting-based strategy to quickly identify the majority element. By sorting the array, the middle element naturally becomes the majority — simple, clean, and surprisingly powerful! 🌟 📊 Complexity Analysis: ⏱ Time Complexity: O(n log n) — due to sorting 💾 Space Complexity: O(1) — constant auxiliary space ✅ Runtime: 7 ms (Beats 39.33%) ✅ Memory: 55.75 MB 🔑 Key Insight: Sometimes the smartest solution is also the simplest — a little ordering can reveal the dominant pattern hiding in plain sight. ✨ #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #CodingDaily #ProgrammingChallenge #Sorting #LogicBuilding #CodeJourney
To view or add a comment, sign in
-
-
🔥 HyperRevision with Structure – Day 87 🔥 🧩 Problem solved today: 1️⃣ Surrounded Regions (LeetCode 130) 💭 Thoughts: Back to Neetcode 150. At first glance, this problem looks just like Number of Islands, but there’s a subtle twist — you need an extra boundary check before marking 'O's as 'X'. The key idea is to start DFS from the border 'O's so that only the inner, fully-surrounded regions are flipped. ⏱️ Time Complexity: O(m × n) 💾 Space Complexity: O(m × n) (due to recursion stack) 📌 GitHub link in comments #HyperRevision #LeetCode #DFS #GraphTraversal #NeetCode150
To view or add a comment, sign in
-
-
🚀 Day 8 of My LeetCode Journey 🔢 Problem #167: Two Sum II - Input Array Is Sorted Today’s challenge was all about leveraging array properties efficiently. The task: given a sorted array, find two numbers that add up to a specific target and return their 1-based indices. 💡 Approach: Two Pointers Since the array is already sorted, we can avoid brute-force and use a two-pointer technique for O(n) time complexity. 🧠 Intuition Start with two pointers: ➡️ left at the beginning and right at the end. If the sum of the two numbers is greater than the target → move right left. If the sum is smaller → move left right. Continue until we find the exact pair. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(1)
To view or add a comment, sign in
-
-
🎯 Day 81 of #100DaysOfCode 🎯 🔹 Problem: Reverse Only Letters – LeetCode ✨ Approach: Used a two-pointer strategy to reverse only the alphabetic characters while keeping all non-letter characters in their original positions. By moving pointers inward and swapping only when both characters are letters, the solution stays efficient and elegant! 🔄✨ 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each character visited at most once 💾 Space Complexity: O(n) — due to character array construction ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 42.96 MB 🔑 Key Insight: Sometimes, all you need is smart pointer movement — not everything needs to be reversed, only the right pieces. #LeetCode #100DaysOfCode #DSA #TwoPointers #StringManipulation #ProblemSolving #CleanCode #AlgorithmDesign #CodingChallenge
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