Codility 'AbsDistinct' Solution

Martin Kysel · August 14, 2014

Short Problem Definition:

Compute number of distinct absolute values of sorted array elements.

AbsDistinct

Complexity:

expected worst-case time complexity is O(N)

expected worst-case space complexity is O(N)

Execution:

Additional storage is allowed. Therefore a simple python solution will suffice.

Solution:

def solution(A):
    return len(set([abs(x) for x in A]))

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.