From 380dba8fa2f0bdf0950104f3329dbebc8a07f961 Mon Sep 17 00:00:00 2001 From: JaiSehgal007 <113134609+JaiSehgal007@users.noreply.github.com> Date: Sat, 29 Oct 2022 17:28:08 +0530 Subject: [PATCH] SOLUTION TO minimum window substring solution to the issue number #773 --- .../MINIMUM WINDOW SUBSTRING.cpp | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Leetcode Solutions/MINIMUM WINDOW SUBSTRING.cpp diff --git a/Leetcode Solutions/MINIMUM WINDOW SUBSTRING.cpp b/Leetcode Solutions/MINIMUM WINDOW SUBSTRING.cpp new file mode 100644 index 00000000..6a0abe6e --- /dev/null +++ b/Leetcode Solutions/MINIMUM WINDOW SUBSTRING.cpp @@ -0,0 +1,59 @@ +/* Author : JaiSehgal007 */ + +/* MINIMUM WINDOW SUBSTRING */ + +/* Link to the Problem : https://leetcode.com/problems/decode-ways-ii/ */ + +/* + +PROBLEM DESCRIPTION:: + +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. If there is no such substring, return the empty string "". + +The testcases will be generated such that the answer is unique. + +*/ + +/* + +SOME PROBLEM RELATED EXAMPLE:: + +Example 1: + +Input: s = "ADOBECODEBANC", t = "ABC" +Output: "BANC" +Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t. +Example 2: + +Input: s = "a", t = "a" +Output: "a" +Explanation: The entire string s is the minimum window. +Example 3: + +Input: s = "a", t = "aa" +Output: "" +Explanation: Both 'a's from t must be included in the window. +Since the largest window of s only has one 'a', return empty string. + +*/ + +/*-------------------------------------SOLUTION----------------------------------------------------*/ +class Solution { +public: + string minWindow(string s, string t) { + vectorfreq(128,0); + for(auto ch:t)freq[ch]++; + int counter=t.size(),begin=0,end=0,d=INT_MAX,head=0; + while(end0)counter--; + while(!counter){ + if(end-begin