From ffe61e80c7285c512b6dc5e1cafec414f58bac0c Mon Sep 17 00:00:00 2001 From: shirali saraf <109896594+shirali-saraf@users.noreply.github.com> Date: Fri, 6 Oct 2023 23:57:25 +0530 Subject: [PATCH] Create cpp program for minimum window substring #773 please assign me this issue . like to contribute the optimized and efficient code in this repo. --- cpp program for minimum window substring | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cpp program for minimum window substring diff --git a/cpp program for minimum window substring b/cpp program for minimum window substring new file mode 100644 index 00000000..bc04d403 --- /dev/null +++ b/cpp program for minimum window substring @@ -0,0 +1,27 @@ +string minWindow(string s, string t) { + if(s.size() < t.size()){ + return ""; + } + unordered_map map; + for(int i=0;i0){ + count++; + } + map[s[end]]--; + if(count == t.length()) { + while(start < end && map[s[start]] < 0){ + map[s[start]]++, start++; + } + if(min_length > end-start){ + min_length = end-(min_start=start)+1; + } + map[s[start++]]++; + count--; + } + } + return min_length == INT_MAX ? "" : s.substr(min_start, min_length); + }