MOHITKUMAR PRAJAPATI’s Post

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

  • graphical user interface, text

Your detailed approach to hard problems reflects genuine growth mindset

To view or add a comment, sign in

Explore content categories