Test case not passing please check

My some test cases are not passing please check

Your code is handling the cases where the string S2 is composed of all discrete letters.
i.e
Test case:
qwerty asdfgh qazxsw
qas
Is working as the string qas doesnot have a repetitive character.
But if I change the test case as:
Test Case:
sqwerty asdfgh sqazxsw
sqas

The code gives wrong answer. It returns:
sqwerty as
But should be returning
sqazxs

this is my updated code still not working please check code ide is https://ide.codingblocks.com/s/138473

Sorry for the delay. Your code is perfect overall, the only thing needs to be fixed is in the following snippet:
else if(position==s2.length()-1) {

            if(right-left<length){
				length=right-left;
				finalleft=left;
                position=0;                 //conditional change for position currently
			}
             //position=0; should be outside if condition
            int k=left+1;
            while(k<right){
                if(s1[k]==s2[position]){
                    
                    left=k;
                    right=k;
                    position++;
                    break;
                }
                k++;
            } 

You will change position=0 even if the substring found is longer than the substring at finalleft variable.
This will fix the code.
Thank You

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.