From f97890409ea64ef9b3039ab04fc77281d43f3c7d Mon Sep 17 00:00:00 2001 From: Naitikdwn <92878102+Naitikdwn@users.noreply.github.com> Date: Fri, 25 Nov 2022 21:13:16 +0530 Subject: [PATCH 1/3] Create Longest Substring Without Repeating Characters --- ...est Substring Without Repeating Characters | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Longest Substring Without Repeating Characters diff --git a/Longest Substring Without Repeating Characters b/Longest Substring Without Repeating Characters new file mode 100644 index 0000000..cb76261 --- /dev/null +++ b/Longest Substring Without Repeating Characters @@ -0,0 +1,25 @@ +class code { +public: + int lengthOfLongestSubstring(string s) { + int wind_start=0; + int max_len=INT_MIN; + map mp; + if(s.size()==0) return 0; + for(int wind_end=0;wind_end Date: Fri, 25 Nov 2022 21:52:19 +0530 Subject: [PATCH 2/3] Updated No Repeat Substring --- ...est Substring Without Repeating Characters | 25 ----------------- NoRepeatSubstring.cpp | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 Longest Substring Without Repeating Characters create mode 100644 NoRepeatSubstring.cpp diff --git a/Longest Substring Without Repeating Characters b/Longest Substring Without Repeating Characters deleted file mode 100644 index cb76261..0000000 --- a/Longest Substring Without Repeating Characters +++ /dev/null @@ -1,25 +0,0 @@ -class code { -public: - int lengthOfLongestSubstring(string s) { - int wind_start=0; - int max_len=INT_MIN; - map mp; - if(s.size()==0) return 0; - for(int wind_end=0;wind_end +using namespace std; + +class NoRepeatSubstring { +public: + static int noRepeatSubstring(string s) { + int windowStart = 0; + int maxLength = INT_MIN; + map indexMap; + if(s.size() == 0) return 0; + + for(int windowEnd = 0; windowEnd < s.size(); windowEnd++) { + char currChar = s[windowEnd]; + if(indexMap.find(currChar) != indexMap.end()) { + windowStart = max(windowStart, indexMap[currChar] + 1); + } + indexMap[currChar] = windowEnd; + maxLength = max(maxLength, windowEnd - windowStart + 1); + } + return maxLength; + } +}; + +int main() { + string s = "abcabcbb"; + cout << NoRepeatSubstring::noRepeatSubstring(s) << endl; +} From 887e8fbe7df7fc8f9363cb627087736750a084a6 Mon Sep 17 00:00:00 2001 From: Aditya Dwivedi <106549312+Lonewolf0502@users.noreply.github.com> Date: Sat, 26 Nov 2022 11:47:56 +0530 Subject: [PATCH 3/3] MinimumSubarrayWithTarget --- MinimumSubarrayWithTarget.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 MinimumSubarrayWithTarget.py diff --git a/MinimumSubarrayWithTarget.py b/MinimumSubarrayWithTarget.py new file mode 100644 index 0000000..b3aa50a --- /dev/null +++ b/MinimumSubarrayWithTarget.py @@ -0,0 +1,29 @@ +#include +using namespace std; + +int MinimumSubarrayWithTarget(vectorvect,int target,int minlen) { + + int windowStart = 0; + int windowSum = 0; + for(int windowEnd = 0; windowEnd < vect.size(); windowEnd++) { + windowSum += vect[windowEnd]; + while(windowSum>=target){ + int windowlength= windowStart-windowEnd+1; + minlen=min(minlen,windowlength); + windowSum -=vect[windowStart]; + windowStart += 1; + } + } + return minlen; + } + + int main() { + vectorvect={3,4,7,1,9,2,12,1}; + int n=vect.size(); + int target=14; + int minlen=INT_MAX; + int ans = MinimumSubarrayWithTarget(vect,target,minlen); + cout<