Ad
  • Custom User Avatar

    Why are all of these solutions O(n^2)?

  • Custom User Avatar

    is it O(N^2) time complexity? O(N) for removing and adding elements to Linked List, bur removing inside forloop... i think O(N * N). Or not?

  • Default User Avatar

    Stevele like your solution man, keep it up.

  • Custom User Avatar

    This is not the most optimized solution, given the constraints of the problem.
    LinkedList remove funtion will traverse the entire list with each call, which is really not needed. Use of an array of size 26 will ensure constant space complexity (as we are not growing linearly) and constant time reach to each character's count (eliminating need for HashMap or something similar).

    You can refer to my solution for comparison. If I am missing some advantage you gain by using linked list, please do reply. I'd love to know! :)

  • Default User Avatar

    This program runs in O(N*M) since
    str1.contains(s) is O(N) with N = length(str1), M = length(str2)

    Using List it takes O(N) only, N = max length of (str1, str2).

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution