-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Add Minimum Window Substring algorithm in Sliding Window package #6553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Minimum Window Substring algorithm in Sliding Window package #6553
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6553 +/- ##
============================================
+ Coverage 75.60% 75.63% +0.03%
- Complexity 5724 5733 +9
============================================
Files 695 696 +1
Lines 19637 19666 +29
Branches 3812 3818 +6
============================================
+ Hits 14846 14874 +28
Misses 4213 4213
- Partials 578 579 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hey @TheAlgorithms @DenizAltunkapan can you review it. I would like to contribute. |
@Anubhav-pandey004 yes, im currently on vacation, so its hard to review it from my phone. Its going to take some time😆 |
src/test/java/com/thealgorithms/slidingwindow/MinimumWindowSubstringTest.java
Show resolved
Hide resolved
@Anubhav-pandey004 I think there might be a possible bug when assertEquals("AABBC", MinimumWindowSubstring.minWindow("AAABBC", "AABC")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
This PR adds an implementation of the Minimum Window Substring problem to the com.thealgorithms.slidingwindow package.
The algorithm finds the smallest substring in s that contains all characters of t.
Time Complexity: O(n) (where n = length of s)
Space Complexity: O(|charset|) (for HashMaps storing frequencies)
Code Summary
Implemented Solution.minWindow(String s, String t) method.
Uses two hash maps:
tFreq → stores required character frequencies of t.
windowFreq → tracks character frequencies in current window.
Expands right pointer until all required characters are included.
Shrinks from left to minimize window length while still valid.
Returns the smallest valid substring, or "" if none exists.