how to get in these types of problems when to shril window when to expand is there any general way so that I can understand it…?? I am struggling in sliding window technique…
Minimum. window substring
There is no hard rule when to expand and when to shrink the window. Its your logic and it will come when you practise 5 to 10 questions on sliding window. Actually sliding window is a very easy concept when you practise some question because all questions follws the same pattern. No new thing will not come in this concept as dynamic programming.
Can you explain how we are shriking window in this problem…
Read this algorithm one time.
- First check if the length of string is less than the length of the given pattern, if yes then “ no such window can exist “.
- Store the occurrence of characters of the given pattern in a hash_pat[].
- Start matching the characters of pattern with the characters of string i.e. increment count if a character matches.
- Check if (count == length of pattern ) this means a window is found.
- If such window found, try to minimize it by removing extra characters from the beginning of the current window.
- Update min_length.
- Print the minimum length window.
in this question if the template string is ttlk then i have to search for ttlk or only t l and k??
so repetition not allowed??only we need to consider occurence??
Yes
The task is to find the smallest window length that contains all the characters of the given string at least one time
For eg. A = “ aabcbcdbca ”, then the result would be 4 as of the smallest window will be “ dbca ”.
If I want all character then how to do. It??
Now able to understand your doubt. One time google your question. There are many questions similar to this question.
Means??? … …
Sir can you clear…??
If you want all character then it is also simple. The also that i give you earlier is for the all character(also for repeated ). If you dont want for repeated character then make the pattern after deleting repeting character. Both question are same with slight modification