Ad
  • Default User Avatar

    Yes, it is very slow, O(n²), and one should use a different solution for bigger lists, eg. using a set/hash table. However, there is no solution with O(log n). You need to look through all items in the list, so you will always have at least O(n). Solutions using sorting (eg. quicksort) or building hash tables will probably have O(n log n) at least.

  • Default User Avatar

    this one is very big brain i like it