Solution to Abs-Distinct by codility

29 Jan

Question: https://codility.com/demo/take-sample-test/abs_distinct

Question Name: AbsDistinct

In the original requirement, expected worst-case space complexity is O(N). But actually, O(1) is enought.

15 thoughts on “Solution to Abs-Distinct by codility

    • Thanks for sharing your solutions!

      FYI: if hash table is permitted, one line in Python is enough:
      return len(set([abs(item) for item in A]))

      I love Pythonnnnn!!!

  1. Scarface, Codility’s complexity detection is just trying to guess (I don’t know how, though) but Sheng’s solution is O(N).

    • I do not know the details neither. But the detection complexity is not very accurate, as I talked with the staffs in Codility.

Leave a Reply

Your email address will not be published. Required fields are marked *