Day 87/100 of DSA & LeetCode grind 🔥 Today's problem: 3318. Find X-Sum of All K-Long Subarrays I What I learned: • It's not always about prefix sums or classic sliding window. • Sometimes the real game is frequency + ordering logic. • For every window of size k, we: Count freq of each number Keep only the top x most frequent values (tie-break by bigger value 😮) Sum value * freq for those Key skills practiced: ✅ HashMap for freq tracking ✅ Sliding window add/remove in O(1) ✅ Custom sorting rule (by freq desc, value desc) ✅ Turning the problem statement into steps that code can actually do Why I liked this problem: This is the type of question that looks like brute force, but teaches you how to maintain state while the window moves. That's super important for real interviews. Mindset: DSA is not just solving one question. It's building patterns you can reuse. Still going. Still consistent. 🚀 #Day87 #LeetCode #DSA #100DaysOfCode #Java #SlidingWindow #ProblemSolving #Consistency
Solved 3318. Find X-Sum of All K-Long Subarrays I with frequency and ordering logic.
More Relevant Posts
-
📌 Day 4/100 - Minimum Size Subarray Sum (LeetCode 209) 🔹 Problem: Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If there’s no such subarray, return 0. 🔹 Approach: Used the Sliding Window technique for an optimized solution: Initialize two pointers (low, high) and a running sum. Expand the window by moving high until the sum ≥ target. Once valid, shrink the window from the left to find the smallest subarray. Keep updating the minimum length throughout. This reduced the time complexity from O(n²) (brute force) to O(n). 🔹 Key Learning: Sliding Window is ideal for problems with contiguous subarrays. Optimization often comes from adjusting the window efficiently. Each problem strengthens logical flow and pattern recognition. Another step forward in mastering DSA and problem-solving consistency! ⚡ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #SlidingWindow
To view or add a comment, sign in
-
-
🌟 Problem 21 – Merge Two Sorted Lists I solved this problem today on LeetCode 💪. It helped me understand how to work with linked lists and how to merge them efficiently. 🧩 Description: Given two sorted linked lists, merge them into one sorted list and return its head. 👉 Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] ✅ Approach: * Compare nodes from both lists one by one. * Add the smaller value to the new list. * Continue until all elements are merged. 📈 Time Complexity: O(n + m) 📦 Space Complexity: O(1) #LeetCode #TopInterview150 #Java #DSA #Coding #ProblemSolving #LinkedList
To view or add a comment, sign in
-
-
💻 Day 11 of #100DaysOfLeetCode – Rotate Image Today’s challenge was “Rotate Image”, a classic matrix manipulation problem that tests both logic and spatial reasoning. 🔹 Problem Statement: Given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) — all in place, without using extra memory for another matrix. 🔹 My Approach (in Java): I used a two-step in-place transformation technique: 1️⃣ Transpose the matrix — swap elements across the diagonal (matrix[i][j] ↔ matrix[j][i]). 2️⃣ Reverse each row — to achieve the 90° clockwise rotation. This approach ensures O(1) extra space and O(n²) time complexity, which is optimal for this problem. 🔹 Key Takeaways: ✅ Learned how matrix transformations can be broken down into simpler operations. ✅ Improved understanding of in-place algorithms and memory efficiency. ✅ Reinforced clean coding habits and edge case handling. Every rotation brings me one step closer to mastering problem-solving patterns! 💪 #100DaysOfLeetCode #CodingJourney #RotateImage #Java #DSA #ProblemSolving #LeetCode #CodingChallenge #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 161 of Coding - Minimum Number of Increments on Subarrays to Form a Target Array (LeetCode - Hard) 🎯 Goal: Find the minimum number of operations required to form a target array starting from an array of zeros, where each operation increments all elements of a chosen subarray by 1. 💡Approach & Debugging: Used a difference-based greedy approach to count only the necessary increments. Steps: Initialize sum with the first element, representing the increments needed for the first number. Traverse the array: Whenever target[i] > target[i - 1], it means additional increments are needed. Add the difference (target[i] - target[i - 1]) to sum. The total sum gives the minimum number of operations required. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. 🧠Key Takeaways: A classic prefix difference trick, focus on the increase, not the absolute value. Greedy approaches often emerge naturally in array transformation problems. #Day161 #LeetCode #GreedyAlgorithm #ArrayProblems #Java #ProblemSolving #DSA #Algorithms #CodingChallenge #InterviewPrep #100DaysOfCode #SoftwareEngineering #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🚀 Day 107 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Decode the String 🟡 Difficulty: Medium 🧠 Approach: Used a stack-based decoding technique to expand encoded patterns of the form k[substring]. 🔹 Traversed the string character by character 🔹 Pushed characters onto a stack until a closing bracket ] was found 🔹 When ] appeared: 1. Extracted the substring inside brackets 2. Retrieved the number (k) indicating repetition 3. Reconstructed the repeated string and pushed it back onto the stack 🔹 After full traversal, combined all characters in the stack to form the decoded result ✅ Handles nested encodings like 3[b2[ca]] ✅ Supports multi-digit counts (e.g., 12[a]) ✅ Efficient string building with StringBuilder ⚡ Complexity: 🕒 Time Complexity: O(N) → Each character is pushed/popped at most once 💾 Space Complexity: O(N) → Stack + output storage 📊 Result: ✔️ 1207 / 1207 test cases passed 📈 Accuracy: 100% Decoding compressed strings using stacks is a great example of parsing + data structure synergy — perfect for interview prep! 💪 #Day107 #gfg160 #GeeksforGeeks #Java #Stack #StringDecoding #ProblemSolving #DSA #CodingChallenge #LearnByDoing #160DaysOfCode #DailyDSA #SoftwareEngineering #TechJourney #Consistency #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
🔥 **Blind 75 Challenge – Day 8: Longest Consecutive Sequence (LeetCode #128)** Today’s problem focuses on **detecting consecutive sequences efficiently** using a HashSet — one of the most elegant O(n) solutions in the #Blind75 list. 🧩 **Problem Statement:** Given an unsorted array of integers, return the length of the longest consecutive elements sequence. You must solve it in **O(n)** time. **Example:** Input: `[100, 4, 200, 1, 3, 2]` Output: `4` (sequence: 1, 2, 3, 4) 💭 **My Approach:** * Store all numbers in a **HashSet** for O(1) lookups * For each number, start counting only if it’s the **beginning of a sequence** (`num - 1` not in set) * Expand forward until the sequence breaks * Track the longest streak 🧠 **Time Complexity:** O(n) 💾 **Space Complexity:** O(n) 💡 **Key Takeaway:** This problem reinforces how **sets and linear scans** can replace nested loops — a simple yet powerful optimization mindset. #LeetCode #DSA #CodingChallenge #Java #ProblemSolving #DailyCoding #CareerGrowth #Blind75
To view or add a comment, sign in
-
-
🚀 Day 63 of My LeetCode journey 🚀 Problem : Custom Sort String Today’s problem was interesting because instead of sorting using normal alphabetical order, we sort the given string based on a custom priority order. 🧠 Problem Understanding Given: order → defines priority of characters. str → the input string which needs to be rearranged. Goal: ✅ Arrange characters of str based on the sequence defined in order. ✅ Characters not present in order should appear at the end (any order). 💡 Approach (Simple & Efficient) Count frequency of each character in str. First append characters following the order. Then append remaining characters. Time Complexity: O(n) Space Complexity: O(1) (fixed array size for 26 letters) ✨ Learnings Sometimes the problem isn't about sorting, but about following a custom priority. Frequency counting is extremely powerful for character-based problems. StringBuilder → best way to build strings efficiently in Java. #leetcode #coding #dsa #java #100DaysOfCode #day63 #learningEveryday #problemSolving
To view or add a comment, sign in
-
-
⚙️ Day 38 of My LeetCode Journey — Problem #2654 “Minimum Number of Operations to Make All Array Elements Equal to 1” (Java Solution) 💡 Today’s challenge beautifully combined number theory with algorithmic optimization. The goal: turn every element in an array into 1 using the minimum operations — and the key insight was rooted in GCD properties. 🔍 My thought process: If any 1s exist → we just need to handle the rest (n - count(1)). Otherwise → find the shortest subarray with GCD = 1, since it’s the only way to generate a 1. The final answer = minimal window length + (n - 1) operations. It’s fascinating how understanding mathematical relationships can drastically simplify code complexity 🔢 Each problem reminds me — elegant logic is what turns code into art 🧠💻 #Day38 #LeetCode #Java #ProblemSolving #NumberTheory #Algorithms #DSA #CodingJourney #100DaysOfCode #CodeEveryday #SoftwareEngineering #LearningInPublic #TechCommunity
To view or add a comment, sign in
-
-
📌 Day 160 of Coding - Reconstruct a 2-Row Binary Matrix (LeetCode - Medium) 🎯 Goal: Reconstruct a 2-row binary matrix given the sums of each column (colsum), and total ones allowed in the upper and lower rows (upper, lower). 💡Approach & Debugging: Used a greedy approach to fill the matrix step by step while maintaining constraints. Steps: Traverse all columns: If colsum[i] == 2, both rows must have 1. Decrease both upper and lower. Traverse again for colsum[i] == 1: Assign 1 to the row with remaining quota (upper first, else lower). If any quota (upper or lower) remains after processing, return an empty list (invalid configuration). Otherwise, return the constructed matrix. ✔️ Time Complexity: O(N) - single traversal of the array. ✔️ Space Complexity: O(N) - to store the two rows. #Day160 #LeetCode #GreedyAlgorithm #Matrix #ProblemSolving #Java #CodingChallenge #DSA #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
#Day23 of my DSA Journey – Longest Repeating Character Replacement 🧩 Problem: Given a string s and an integer k, you can change at most k characters to make all letters in a substring the same. Return the length of the longest possible substring after those changes. ⚙️ Approach: Use the Sliding Window technique with a frequency array. Keep track of the most frequent character — if the rest exceed k, shrink the window. 💡 Key Idea: (window length - maxFreq) <= k ensures valid window size. ✅ Output Example: s = "AABABBA", k = 1 → 4 #DSA #Java #SlidingWindow #CodingChallenge #LeetCode #ProblemSolving #100DaysOfCode
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