Computer Science, asked by jatindersingh1069, 1 year ago

Write a program to find the number of distinct elements in the sorted array

Answers

Answered by Anonymous
2

Answer:

C++ program to print all distinct elements in a given array ... Check if the picked element is already printed .... We can Use Sorting to solve the problem in O(nLogn) time.

Answered by sushiladevi4418
0

Answer:

Python program to find the number of distinct elements in the sorted array.

Explanation:

# This function returns number of

# distinct absolute values among

# the elements of the array

def distinctcount(arr, n):  

   s = set()  

     

   # set keeps all unique elements  

   for i in range(n):  

       s.add(abs(arr[i]))  

   return len(s)  

 

# Driver Code  

arr = [-2, -1, 0, 1, 1]  

n = len(arr)  

print("Count of absolute distinct values:",  

                    distinctcount(arr, n))

Similar questions