📘 DSA Journey — Day 20 Today’s focus: Sliding Window with frequency constraints. Problem solved: • Maximum Number of Occurrences of a Substring (LeetCode 1297) Concepts used: • Sliding Window technique • Frequency tracking using HashMap / array • Substring counting Key takeaway: The goal is to find the maximum frequency of any substring that satisfies: • At most maxLetters distinct characters • Length between minSize and maxSize A key observation simplifies the problem: We only need to check substrings of size minSize, because larger substrings will have equal or lower frequency. Using a sliding window of fixed size minSize, we: • Track character frequencies inside the window • Ensure the number of distinct characters ≤ maxLetters • Count valid substrings using a HashMap This avoids checking all possible substring sizes and reduces complexity significantly. This problem highlights how constraints can reduce the search space, making sliding window solutions more efficient. Continuing to strengthen pattern recognition and consistency in solving DSA problems. #DSA #Java #LeetCode #CodingJourney
Max Substring Frequency with Constraints
More Relevant Posts
-
🔥 DSA Challenge – Day 136/360 🚀 📌 Topic: Bit Manipulation 🧩 Problem: Number of 1 Bits (Hamming Weight) Problem Statement: Given an integer, return the number of set bits (1’s) present in its binary representation. 🔍 Example: Input: 6 Output: 2 Explanation: Binary of 6 → 110 → 2 set bits 💡 Optimized Approach (Brian Kernighan’s Algorithm): Instead of checking each bit one by one, we use a smart trick: n & (n - 1) removes the rightmost set bit in each iteration This reduces the number of operations to the number of set bits only ⚡ Time Complexity: O(k) (k = number of set bits) ⚡ Space Complexity: O(1) 🚀 Key Takeaway: Using bit manipulation can drastically optimize performance compared to brute force approaches. Always look for patterns in binary operations! #DSA #Coding #Java #BitManipulation #136DaysOfCode #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 135/360 🚀 📌 Topic: Bit Manipulation 🧩 Problem: Check if a Number is Power of 2 Problem Statement: Given an integer n, determine whether it is a power of 2 or not. 🔍 Example: Input: n = 4 Output: true Input: n = 6 Output: false 💡 Approach: Optimized (Bit Manipulation) 1️⃣ Step 1 – If n <= 0, return false (powers of 2 are always positive) 2️⃣ Step 2 – Use bit trick: n & (n - 1) removes the lowest set bit 3️⃣ Step 3 – If result becomes 0, then only one set bit was present ✔ This avoids looping and works in constant time ⏱ Complexity: Time: O(1) Space: O(1) 📚 Key Learning: A number is a power of 2 if it has exactly one set bit in binary representation. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #135DaysOfCode #BitManipulation #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 56 of #100DaysOfLeetCode Solved: Longest Substring Without Repeating Characters Today’s problem really tested my understanding of the sliding window technique. 🔹 Key Learning: Instead of restarting the window when a duplicate appears, I used a HashMap to track the last index of characters and moved the left pointer smartly using Math.max(). This helped maintain an optimal window without unnecessary rework. 🔹 Approach: Used two pointers (left & right) Stored last seen index of each character Adjusted window dynamically to avoid duplicates 🔹 Complexity: Time: O(n) Space: O(n) This problem made me realize how important it is to truly understand pointer movement rather than just memorizing patterns. Slowly building consistency and clarity, one problem at a time. #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 44 #SDE sliding window techniques and optimization problems. Solved: • Longest Substring Without Repeating Characters • Maximum Points You Can Obtain from Cards Key Learning: • “Longest Substring Without Repeating Characters” is a classic sliding window + hashing problem, where we dynamically adjust the window to maintain unique characters. • “Maximum Points from Cards” uses a clever window optimization, where instead of picking k cards directly, we minimize the sum of the remaining subarray. #LeetCode #DSA #SlidingWindow #Algorithms #Java #SoftwareEngineering
To view or add a comment, sign in
-
Day 41 #SDE stack-based validation and dynamic programming on strings. Solved: • Bracket Challenge • Word Break Key Learning: • “Bracket Challenge” reinforces the use of a stack to validate balanced parentheses and handle nested structures efficiently. • “Word Break” revisited the DP + memoization approach, where we check valid segmentations of a string using a dictionary. #LeetCode #DSA #Stack #DynamicProgramming #Algorithms #Java #SoftwareEngineering
To view or add a comment, sign in
-
Day 82 of DSA Journey Solved Isomorphic Strings today! This problem looks simple, but it teaches an important concept — one-to-one mapping between characters. 🔍 What I learned: Each character in one string must map to exactly one character in the other No two characters should map to the same character Consistency across the entire string is key 💡 Approach: Used two HashMaps to track mappings in both directions: s → t t → s This avoids conflicts and ensures correctness. 🧠 Example: "paper" → "title" ✅ "foo" → "bar" ❌ ✨ Key takeaway: Always think about bidirectional mapping when dealing with transformation problems. Small problem, but powerful concept! #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
📊 DSA Progress Update – Week 5 Over the past few days, I’ve been practicing array problems and improving my approach step by step. What I learned: • Starting with a brute force solution helps in understanding the problem clearly • Optimization becomes easier once the pattern is identified • Key techniques : - Two Pointers - Sliding Window - Prefix Sum - Kadane’s Algorithm Something new: Started learning Binary Search and understanding its basic approach. Plan: Continue practicing and get more comfortable with these concepts. Taking it one step at a time. #DSA #Java #LeetCode #Consistency #CodingJourney
To view or add a comment, sign in
-
🚀 Day 13 – DSA Practice Today I explored the Sliding Window technique using the problem: Maximum Sum Subarray of Size K 📌 Problem: Given an array and a window size k, find the maximum sum of any subarray of size k. 💡 Approach: Instead of recalculating sum every time, maintain a window sum: • Add next element • Remove previous element This helps process the array in a single pass ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This problem helped me understand how sliding window optimizes subarray problems efficiently. #Java #DSA #SlidingWindow #CodingInterview #ProblemSolving
To view or add a comment, sign in
-
-
DSA Practice Update Today I solved: #141 – Linked List Cycle Learned how to detect a cycle in a linked list using Floyd’s Cycle Detection Algorithm (fast and slow pointers). Understood how moving pointers at different speeds helps identify if a loop exists without using extra space. Key Learnings: • Fast and slow pointer technique • Detecting cycles efficiently in O(n) time • Solving problems with constant space complexity This problem strengthened my understanding of pointer-based approaches, which are commonly used in linked list interview questions. Continuing to stay consistent and improve problem-solving skills step by step. #DSA #LeetCode #CodingJourney #Java #SoftwareDevelopment #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 8 of #100DaysOfDSA Today’s problem: Longest Substring Without Repeating Characters 🧠 Problem Statement: Given a string, find the length of the longest substring without repeating characters. 💡 Approach: Sliding Window Technique Used two pointers (left & right) Maintained a HashSet to track characters Expanded window when unique Shrunk window when duplicate found ⚡ Key Learning: Efficient use of the sliding window helps reduce time complexity to O(n), which is crucial for optimizing string-based problems. 💻 Example: Input: "abcabcbb" Output: 3 ("abc") 🔥 This problem strengthened my understanding of: ✔️ Two-pointer technique ✔️ Hashing (Set/Map) ✔️ Optimizing brute force solutions Consistency is the key — small steps every day lead to big results 💪 #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode 🍁 Saidhanya Sree
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