`{"id":"676f9a80-08c2-4606-9d35-80ca3b2a0bce","name":"Distinct Absolute Array Elements","description":"Given a sorted array of size N. Count the number of distinct absolute values present in the array.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^5\r\n-10^8 &lt;= Arr[i] &lt;= 10^8\r\nThe array may contain duplicates","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nint count(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n // input work\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n cout << count(arr) << endl;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int count(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(count(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n-3 -2 0 3 4 5","sampleOutput":"5","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"3689dd4a-f663-4fc0-899c-e7cdbfe651b5","name":"Distinct Absolute Array Elements","slug":"distinct-absolute-array-elements","type":1}],"next":{"id":"fd3354c9-55db-49d1-8c1e-17a47fe3aa40","name":"Distinct Absolute Array Elements","type":3,"slug":"distinct-absolute-array-elements"},"prev":{"id":"57e08ef8-ccd8-47f2-9b77-61e84b26e663","name":"Facing The Sun MCQ","type":0,"slug":"facing-the-sun-mcq"}}}`

# Distinct Absolute Array Elements

Given a sorted array of size N. Count the number of distinct absolute values present in the array.

`{"id":"676f9a80-08c2-4606-9d35-80ca3b2a0bce","name":"Distinct Absolute Array Elements","description":"Given a sorted array of size N. Count the number of distinct absolute values present in the array.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^5\r\n-10^8 &lt;= Arr[i] &lt;= 10^8\r\nThe array may contain duplicates","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nint count(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n // input work\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n cout << count(arr) << endl;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int count(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(count(arr));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n-3 -2 0 3 4 5","sampleOutput":"5","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"3689dd4a-f663-4fc0-899c-e7cdbfe651b5","name":"Distinct Absolute Array Elements","slug":"distinct-absolute-array-elements","type":1}],"next":{"id":"fd3354c9-55db-49d1-8c1e-17a47fe3aa40","name":"Distinct Absolute Array Elements","type":3,"slug":"distinct-absolute-array-elements"},"prev":{"id":"57e08ef8-ccd8-47f2-9b77-61e84b26e663","name":"Facing The Sun MCQ","type":0,"slug":"facing-the-sun-mcq"}}}`

Editor

# Distinct Absolute Array Elements

medium

Given a sorted array of size N. Count the number of distinct absolute values present in the array.

## Constraints

1 <= N <= 10^5 -10^8 <= Arr[i] <= 10^8 The array may contain duplicates

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 -3 -2 0 3 4 5```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}5`

Discussions

Show Discussion

Related Resources