Given a sorted array of integers, return the number of distinct absolute values among the elements of the array. The input can contain duplicates values.
Input: [-3, -2, 0, 3, 4, 5] Output: 5 There are 5 distinct absolute values among the elements of this array, i.e. 0, 2, 3, 4 and 5) Input: [-1, -1, -1, -1, 0, 1, 1, 1, 1] Output: 2 Input: [-1, -1, -1, -1, 0] Output: 2 Input: [0, 0, 0] Output: 1http://www.geeksforgeeks.org/absolute-distinct-count-array-sorted-absolute-values/
No comments:
Post a Comment