Skip to content

Conversation

Anubhav-pandey004
Copy link
Contributor

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.63%. Comparing base (f43ecd5) to head (235d2fa).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Anubhav-pandey004
Copy link
Contributor Author

hey @TheAlgorithms @DenizAltunkapan can you review it. I would like to contribute.

@DenizAltunkapan
Copy link
Member

@Anubhav-pandey004 yes, im currently on vacation, so its hard to review it from my phone. Its going to take some time😆

@DenizAltunkapan
Copy link
Member

@Anubhav-pandey004 I think there might be a possible bug when t has duplicate chars (e.g. "AABC"). Please verify by adding a test:

assertEquals("AABBC", MinimumWindowSubstring.minWindow("AAABBC", "AABC"));

Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DenizAltunkapan DenizAltunkapan enabled auto-merge (squash) October 2, 2025 18:22
@DenizAltunkapan DenizAltunkapan merged commit 977c982 into TheAlgorithms:master Oct 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants