Write a program to find the number of distinct elements in the sorted array
Answers
Answered by
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
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