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

More Cognizant coding questions