human
Count distinct elements in an array | This function prints all distinct elements.
Creates an empty hashset.
Traverse the input array.
If not present , then put it in hashtable and increment result.
Driver code"
Solution in Python:
assistant
#Here is code to count distinct elements in an array and the other steps required.
 def countDistinct ( arr , n ) :
	s = set ( )
	res = 0
	for i in range ( n ) :
		if ( arr [ i ] not in s ) :
			s . add ( arr [ i ] )
			res += 1
	return res
arr = [ 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 ]
n = len ( arr )
print ( countDistinct ( arr , n ) )