Count Triplets

  • + 3 comments

    This solution, like many others, claims to be O(n) because there is only one 'for' loop involved. But that idea is totally flawed because, the access in dictionary (or STL maps in C++)is O(log(n)). This means the overall worst case complexity when all the elements are distinct, is O(nlog(n)).