Short Problem Definition:
Compute number of distinct absolute values of sorted array elements.
expected worst-case time complexity is O(N);
expected worst-case space complexity is O(N)
Additional storage is allowed. Therefore a simple python solution will suffice.
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.