Failing Perfect cases

from collections import Counter
def find_anagrams(p, s):
    result = []
    for i in range(0, len(s)-len(p)+1):
        new_string = s[i:i+len(p)]
        if Counter(new_string) == Counter(p) :
            result.append(i)
    print("result",result)
    return(result)


def main():
    s, p = input().split()
    answer = find_anagrams(p, s)
    print(len(answer))
    print(' '.join([str(i) for i in answer]))


if __name__ == "__main__":
    main()

can someone tell me and also is this approach is right?

Hey Shubham,
The approach is absolutely correct for small testcases.
But for large testcases it fails.
The time complexity of your approach is O(NM) where N is the length of the string and M is the length of the pattern. Try to reduce the time compexity.

Also, it would be appreciated if you do not post the solution here. Either snippets or problem statement would work.

ok.
will try to reduce the complexity.
yeah sure. i will not post the solution.
Thanks.

@shubham007 Were you able to resolve this?

not yet…i was trying to resolve other problems.
once i will try to do and if i not to able to complete i will ask for help in slack or forum.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.