From c6a454590da4ce86b0f61fac4b567824d46d9752 Mon Sep 17 00:00:00 2001 From: AMIT KUSHWAHA Date: Wed, 5 Oct 2022 01:35:38 +0530 Subject: [PATCH] chore(CPlusPlus): add sliding windows (#853) --- algorithms/CPlusPlus/README.md | 2 + .../CPlusPlus/Strings/sliding-window.cpp | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 algorithms/CPlusPlus/Strings/sliding-window.cpp diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 6a713e39..13139d2d 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -33,6 +33,7 @@ - [Sparse Matrix](Arrays/sparse_matrix.cpp) + ## Dynamic-Programming - [Longest Common Subsequence](Dynamic-Programming/longest-common-subsequence.cpp) @@ -128,6 +129,7 @@ - [Boyer Moore pattern search](Strings/Boyer_Moore.cpp) - [Longest common prefix](Strings/longest-common-prefix.cpp) - [First unique character in the string](Strings/first-unique-character.cpp) +- [Sliding Window to match target string](Strings/sliding-window.cpp) ## Trees diff --git a/algorithms/CPlusPlus/Strings/sliding-window.cpp b/algorithms/CPlusPlus/Strings/sliding-window.cpp new file mode 100644 index 00000000..a5f60cd4 --- /dev/null +++ b/algorithms/CPlusPlus/Strings/sliding-window.cpp @@ -0,0 +1,42 @@ +/* +Description: A program to find target sub string in given string + +Approach: Using sliding window technique to compare every possible substring with the target string. +It also supports variable length target inputs since we are initialising window size with size of target + +Time complexity: O(n) +*/ + +#include +#include + +using namespace std; + +void sliding(string s,string target){ + int window_size=target.size(); + bool notfound=true; + for(int i=0;i>target; + + sliding(s,target); + + return 0; +} \ No newline at end of file