String Window wrong answer on two test cases

I am getting WA on test 2 and 6
My code: https://ide.codingblocks.com/s/147699

Hello @17uec133,

You are required to return the minimum length substring of the given string that contains all the characters of the pattern.
Instead, your code is returning the last detected substring containing all characters irrespective of its length.
The logic for minimum length is missing.
Example 1
qwerty asdfgh qazxsw
qta
Your Output:
ty asdfgh q
Expected Output:
qwerty a

Example 2:
Hello Utkarsh Raj
ar
Your Output:
rsh Ra
Expected Output:
ar

Hope, this would help.
Give a like if you are satisfied.

1 Like

thanks. Now I realise I was doing this completely wrong

@17uec133 Anytime,

Please, mark it as resolved.
BTW, I won’t mind a like. :joy:

1 Like

I have tried using another approch. Last time I was getting 80 points. But this time I am getting 20:sweat_smile:
Please check my code and do give some hints
https://ide.codingblocks.com/s/148656

Hey @17uec133,

Have you corrected the previous code?
Also, explain the logic you are implementing for the second approach.

Every time I am finding a new window which contains all the characters of second string I am checking whether its length is smaller than the previous windows. If it is smaller then I am changing the start and end index. Every time I am finding a new window which contains all the characters of second string, I am also checking whether some unnecessary characters can be removed from this window to make its length as small as possible.

Hello @17uec133,

  1. The output format for the case If no such substring exist is wrong
    Output “No string” instead of “No suggestion”

  2. Your code only accounts for lowercase letters
    Example:
    AabaA
    aA
    Expected Output:
    Aa
    Your Output:
    No string

Correct these first.


Still not correct. I am stuck in this problem from past 5 days

Hello @17uec133,

There are problems in which you would stick for long.
But, patience is very important in such situations.

BTW, you have modified your code as suggested by me in my previous reply.
Now, you have reduced the no. of wrong test cases to 3. Great.:v:

Your code is logically correct now with two mistakes that we have to eliminate:

  1. Consider ’ ’ (spaces also)

  2. Initialize ss to 0 instead of assigning it the value of s.
    Reason:
    To keep ss modified even if this if(i - ss + 1 < len) consition doesn’t satisfy.

I have modified your code:


It is passing all the test cases.

Give a like if you are satisfied.

1 Like

Hey
Thanks a lot for replying on all the questions. A big like for you. :smiley:

Anytime @17uec133,

Please, mark it as resolved.