• + 5 comments

    What is the time complexity if I write the code in this way:

    A = set(socks)
    for element in A:
    	pairs += socks.count(element) // 2
    print(pairs)
    

    It should be O(n), but the space complexity increases since we create a space for A? Am I correct? Thanks for any suggestions.