Codility ‘AbsDistinct’ Solution

Short Problem Definition:

Compute number of distinct absolute values of sorted array elements.

Link

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]))

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

Facebooktwittergoogle_plusredditpinterestlinkedin