What's wrong with my approach for WSITE01.. plz help me

problem link WSITES01

myCode Link
My code is giving Correct Answer for all test cases Cheked by me but it is not passing all cases for codechef
i tried a lot to found where my code is failing but dont know why
plz help me

alt text

Check this one:
3

  • siddharth
  • sidklmno
  • pandey
    Output should be
    1
    sidd
    and not
    1
    siddh
    I think what you are doing is checking whether all unblocked[i] contains the blocked[i] but along the way you also need to eliminate the strings whose unblocked[i]!=blocked[i] and only check for the remaining ones.
    Hope this helps :slight_smile:
1 Like

I believe it fails here-

Input
4
 + hackerrank
 - hackerrankz
 + ae
 - a

Output
1
hackerrankz

Expected Output
-1

I believe that we have to include “ae” but block “a”, but “a” is a prefix of “ae”, so its not possible to block all bad sites without blocking a good one. So we print -1.

1 Like

@vijju123 i am sure… u havn’t submitted this question till now… output will be -1 when no filter is created… here hackerrankz filter is created so output will 1

@siddharthp538 ty bro… u nailed it

No dear, i cross-checked it with correct programs. The output is -1.

Here is what Q said-

If it is not possible to choose set of filters and satisfy all constraints, output a single line containing an integer -1.

And constraints were-

A filter is a string that should be a prefix of some blocked site, and it should not be a prefix of any unblocked site

You cannot block “a” without blocking “ae”

@vijju123 okey bro… i will give another shot to problem

Yes, try giving it a shot with this in mind :slight_smile:

No problem :slight_smile: