Minimum Window Substring Solution for Cognizant
Company: Cognizant · Difficulty: Hard · Topics: String, Sliding Window, Hash Table, Two Pointers
Problem Statement
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window.
Examples
Example 1:
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Example 2:
Input: s = "a", t = "a"
Output: "a"
Approach
Use a sliding window approach with two pointers (left and right) and frequency tracking.
Time and Space Complexity
- Time Complexity: O(m + n) where m and n are lengths of s and t
- Space Complexity: O(k) where k is the number of unique characters