P20845 [GeeksforGeeks] Absolute distinct count5118
普及-
题目描述

Given a sorted array of N integers, find the number of distinct absolute values among the elements of the array.
Example 1:
Input:
N = 6
arr[] = {-3, -2, 0, 3, 4, 5}
Output: 5
Explanation: There are 5 distinct absolute
values among the elements of this array,
i.e. 0, 2, 3, 4 and 5.
Example 2:
Input:
N = 9
arr[] = {-1, -1, -1, -1, 0, 1, 1, 1, 1}
Output: 2
Explanation: There are 2 distinct absolute values
among the elements of this array, i.e. 0 and 1.
Your Task:
You don't need to read input or print anything. Complete the function distinctCount() which takes the array of integers arr[] and its size n as input parameters and returns the number of distinct absolute values.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ |Arr[i]| ≤ 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 6 arr[] = {-3, -2, 0, 3, 4, 5}
样例输出
5