Sir before entering if(count==PL)
the FS would be {e:1 ,a:1 , f:1 ,b:1 ,c:1 , g:1}
this array would make count==PL
but the while loop wont work
it doesnt satisfy any condition given in while loop
Sir before entering if(count==PL)
the FS would be {e:1 ,a:1 , f:1 ,b:1 ,c:1 , g:1}
this array would make count==PL
but the while loop wont work
it doesnt satisfy any condition given in while loop
Hi, your doubt is not clear to me. Do you want me to debug your code or something?
Nope sir dry run for a single test case
Please be patient while I type.
Okay, letβs say that the testcase is
string s=" eafbcgdefg";
string p="efg";
Therefore, FP[βeβ] = FP[βfβ] = F[βgβ] = 1 and rest all are 0.
now, for i = 0,
ch = β β (space)
as FP[ch] = 0, count does not update and is still 0.
now count is != PL, therefore the if block is not executed.
for i = 1, ch = βeβ, therefore count increments to 1, and if block is still no executed.
for i = 2, ch = βaβ, but FP[ch] = 0, so nothing happens
for i = 3, ch = βfβ, count increments to 2
for i = 4 and 5, nothing happens
for i = 6, ch = βgβ, count increments to 3,
also count == PL, therefore we execute the if block now,
start = 0
what the while loop does is to increase the start as long as the characters are contained,
as s[start] is useless and can be discarded, we increment start to 1
now, s[start] = s[1] = βeβ, is required so we canβt proceed any further and the loop ends.
Now, we compare the answers with int window_len = i-start+1;
, if smaller we update the answer and so on.
so why it is giving efg as output ?
then it should give the window starting from the initial index
Because, I didnβt dry run till the end, where there is βefgβ.
Do you want me to dry run for that part as well?
yes sir please dry run for the output efg !
now for i = 7, ch = βdβ, nothing happens to count (it is still = 3)
we go into the if block, and start = 1,
therefore temp = s[start] = βeβ, the while condition
while( FP[temp]==0 || FS[temp]>FP[temp])
is not satisfied for this and the loop therefore never runs.
i = 8, ch = βeβ, FS[βeβ] becomes 2 now, the count still remains the same (= 3),
we go into if block, and start = 1,
for i = 9, ch = βfβ, β¦ (try to dry run from here, because it is the final part and it will be beneficial if you try this on your own)
If you still canβt do it, reach back to me, Iβll be happy to help.
thank you so much understood , i thought count is npot decrememnting how it is handled is now known .