Day 55/100 | #100DaysOfDSA 🔄🧠 Today’s problem: Permutation in String A classic sliding window + frequency count problem. Core idea: We need to check if any permutation of s1 exists as a substring in s2. Approach: • Maintain a frequency array for s1 • Use a sliding window over s2 • Expand the window by moving right pointer • If frequency becomes invalid → shrink from left • If window size matches s1 → valid permutation found Key insight: Instead of generating all permutations (which is expensive), we match character counts dynamically. Time Complexity: O(n) Space Complexity: O(1) (fixed size array of 26) Big takeaway: Sliding window + frequency tracking is a powerful combo for substring problems. These pattern-based problems are getting sharper day by day. 🔥 Day 55 done. #100DaysOfCode #LeetCode #DSA #Algorithms #SlidingWindow #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Permutation in String: Sliding Window Approach
More Relevant Posts
-
🔄 Solved “Spiral Matrix”, a classic matrix traversal problem using boundary-based approach. ✦ What This Problem Taught Me: • How to traverse a 2D matrix layer by layer using boundaries • Effective use of four pointers (top, bottom, left, right) • Managing direction-based traversal (→ ↓ ← ↑) • Importance of shrinking boundaries after each iteration • Avoiding duplicate traversals using proper conditions • Strengthened understanding of 2D arrays and indexing 🚀 Problems like this show how controlling boundaries and direction can simplify complex matrix traversals into a clean O(m × n) solution. On to solving more matrix and pattern-based problems 💪🔥 #LeetCode #DSA #Matrix #TwoPointers #CodingJourney #ProblemSolving #Java #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 76 of #100DaysOfCode Solved 725. Split Linked List in Parts on LeetCode 🔗 🧠 Key Insight: We need to split a linked list into k parts such that: 👉 Sizes are as equal as possible 👉 Earlier parts can have at most one extra node ⚙️ Approach (Length + Distribution): 1️⃣ Find length of linked list → len 2️⃣ Compute: 🔹 partSize = len / k 🔹 extra = len % k 👉 First extra parts will have partSize + 1 nodes 3️⃣ Traverse and split: 🔹 For each part: • Assign size = partSize + (extra > 0 ? 1 : 0) • Move pointer that many nodes • Break link (next = null) • Decrement extra 4️⃣ If len < k: 🔹 Some parts will be null ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) (result array) #100DaysOfCode #LeetCode #DSA #LinkedList #Simulation #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 46/75 — Frequency of the Most Frequent Element Today’s problem was about maximizing the frequency of an element using at most k increments. Approach: • Sort the array • Use sliding window • Maintain sum of current window • Expand right pointer • Shrink window when operations exceed k Key logic: while ((long) nums[right] * (right - left + 1) - total > k) { total -= nums[left]; left++; } maxFreq = Math.max(maxFreq, right - left + 1); Time Complexity: O(n log n) (sorting) Space Complexity: O(1) Key Insight: Make all elements in window equal to the largest element — check if cost ≤ k. 46/75 🚀 #Day46 #DSA #SlidingWindow #TwoPointers #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 59 – Spiral Matrix II Worked on generating an n×n matrix filled in spiral order using boundary-based traversal. Key Learnings: Learned to manage four boundaries (top, bottom, left, right) for controlled traversal Understood how to fill matrices layer by layer in a spiral pattern Improved handling of edge cases using boundary checks Strengthened understanding of direction-based movement in matrices #DSA #Java #Matrix #Arrays #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
Day 75/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Count the Number of Inversions A challenging problem combining permutations + constraints + DP. Problem idea: Count the number of permutations such that given prefixes have exactly certain inversion counts. Key idea: Dynamic Programming on permutations + inversion count tracking. Why? • We need to build permutations step by step • Each insertion affects inversion count • Constraints restrict valid states → perfect for DP How it works: • Let dp[i][j] = number of ways to form first i elements with j inversions • When adding a new number, it can create multiple inversions depending on position • Transition by inserting element at all valid positions • Apply constraints from requirements at specific indices • Use modulo to handle large results Time Complexity: O(n * maxInv * n) Space Complexity: O(n * maxInv) Big takeaway: When problems involve counting permutations with constraints, think of DP + state representation (like inversions, subsets, etc.). This pattern is common in advanced combinatorics problems. 🔥 Day 75 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #DynamicProgramming #Combinatorics #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🎉🎉 Day-32 of #60DaysOfDSA 🎉🎉 Problem: K-th Element of Two Sorted Arrays 👉 Problem Statement: Given two sorted arrays, find the element that would appear at the k-th position in the merged sorted array. 👉 Approach Used (Two Pointer / Merge Logic): ✔️ Use two pointers i and j for both arrays ✔️ Traverse like merge step of merge sort ✔️ Keep counting elements until count == k ✔️ Return the k-th element 👉 Time Complexity : O(n + m) #dsa #problemsolving #java #geekstreak60
To view or add a comment, sign in
-
-
Day 48/75 — Max Consecutive Ones III Today’s problem was about finding the maximum consecutive 1s after flipping at most k zeros. Approach: • Use sliding window • Expand right pointer • Count zeros in window • Shrink window when zeros > k Key logic: if (nums[right] == 0) zeroCount++; while (zeroCount > k) { if (nums[left] == 0) zeroCount--; left++; } maxLength = Math.max(maxLength, right - left + 1); Time Complexity: O(n) Space Complexity: O(1) Key Insight: Keep the window valid by ensuring at most k zeros, and maximize its size. 48/75 🚀 #Day48 #DSA #SlidingWindow #TwoPointers #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
🎉🎉 Day-30 of #60DaysOfDSA 🎉🎉 Problem: Largest Rectangle in Histogram 👉 Problem Statement: Given an array arr[] representing heights of histogram bars, find the largest rectangular area that can be formed. Each bar has width = 1. 👉 Optimized Approach (Monotonic Stack): ✔️ Use a Stack to store indices of increasing heights ✔️ Traverse the array: While current height is less than or equal to stack top: Pop the stack Calculate area: height = popped bar width = i - stack.peek() - 1 ✔️ Update maximum area ✔️ Push current index ✔️ After traversal, process remaining elements in stack 👉 Time Complexity : O(n) #geekstreak60 #java #problemsolving #dsa
To view or add a comment, sign in
-
-
🚀 Day 75 of #100DaysOfCode Solved 103. Binary Tree Zigzag Level Order Traversal on LeetCode 🔗 🧠 Key Insight: This is a variation of level order traversal where: 👉 Levels alternate between left → right and right → left ⚙️ Approach (BFS + Direction Toggle): 1️⃣ Use a queue for level order traversal 2️⃣ Maintain a flag (leftToRight or sign) 🔹 true → left → right 🔹 false → right → left 3️⃣ For each level: 🔹 Create a list 🔹 Traverse all nodes in that level 4️⃣ Insert values based on direction: 🔹 If left → right → addLast(val) 🔹 Else → addFirst(val) 5️⃣ Add level list to result 6️⃣ Flip direction: 👉 sign *= -1 or toggle boolean ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #100DaysOfCode #LeetCode #DSA #BinaryTree #BFS #Queue #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 75/100 🚀 | #100DaysOfDSA Solved LeetCode 378 – Kth Smallest Element in a Sorted Matrix today. The problem was to find the k-th smallest element in an n x n matrix where each row and column is sorted. Approach: Used Binary Search on the value space (not indices). • Defined the search range from the smallest element (matrix[0][0]) to the largest (matrix[n-1][n-1]) • For each mid, counted how many elements in the matrix are ≤ mid • If count < k → move right (left = mid + 1) • Else → move left (right = mid) For counting, used an efficient bottom-left traversal: • Started from bottom-left corner • If current element ≤ mid → all elements above are valid → add count and move right • Else → move up This avoids checking all elements and keeps it efficient. Time Complexity: O(n log(max - min)) Space Complexity: O(1) Key takeaway: Binary Search isn’t just for arrays — it can be applied on the answer space, especially when the matrix has sorted properties. #100DaysOfDSA #LeetCode #DSA #Java #BinarySearch #Matrix #ProblemSolving #Consistency
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