Actually I had 2 doubts…
1st-> my code is partially correct and I am not able to find mistake in it.
2nd-> I want to know that I have used code with complexity O(n^2) and I want to know if there is a better way to do it.
Actually I had 2 doubts…
1st-> my code is partially correct and I am not able to find mistake in it.
2nd-> I want to know that I have used code with complexity O(n^2) and I want to know if there is a better way to do it.
Try to follow this :
1.First check if length of string is less than the length of given pattern, if yes then "no such window can exist ".
2.Store the occurrence of characters of given pattern in a hash_pat[].
3.Start matching the characters of pattern with the characters of string i.e. increment count if a character matches
4.Check if (count == length of pattern ) this means a window is found
5.If such window found, try to minimize it by removing extra characters from beginning of current window.
6.Update min_length
7.Print the minimum length window.
O(n^2) solution!
If you are still unable to code this algorithm, please have a look at this implementation.
Could you please help me in debugging…because I didn’t get the mistake…
I want to know the test cases for which my output is wrong!
I got my mistake…and it’s due to unclarity in the statement …it says that you need to find sring which has all elements of it
hence for ABC A as string 1 . and AA as string 2 the answer it ABC A…and acc. to the question statement A must be accepted
Sorry for a late response. Its great you have found your mistake yourself.
I can understand its a little confusing. I’ll ask concerned department to change the problem statement.