Gaurav Sharma’s Post

#Day9 of my #100DaysCodingChallenge 💻 Today’s problem pushed my reasoning around frequency analysis and window-based computation — a brilliant mix of hashmaps and sliding window logic! 🧮⚙️ 🔍 Problem Explored: Find X-Sum of All K-Long Subarrays — where for every subarray of length k, you need to compute the sum of the top x most frequent (and largest, if tied) elements. 💡 Approach: For each subarray, counted element frequencies using a HashMap, then sorted entries by frequency (and value on ties) to pick the top x contributors. Finally, optimized the logic with sliding windows to reuse previous computations efficiently. ⏱ Time Complexity: O(n × k log k) (initial) → optimizable using ordered maps or heaps 🧠 Space Complexity: O(k) ✅ Result: Implemented a clear and correct Java solution that balances frequency tracking with subarray iteration — a great hands-on dive into map manipulation and priority-based logic. 📘 Learning: When dealing with frequency-based problems, structuring data efficiently is half the battle. A well-placed map or heap can turn a brute-force approach into an elegant one. 🙌 Special thanks to K.R. Mangalam University and Abhishek Kumar Sir for continuously motivating me to refine my logic and efficiency. #Java #CodingChallenge #100DaysOfCode #ProblemSolving #LeetCode #CompetitiveProgramming #DSA #InterviewPrep #SlidingWindow #HashMap #FrequencyAnalysis #CodingJourney #LearningEveryday

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories