Number of non-unique elements hackerrank - Python
Problem Definition: We have to find here the number of non unique elements (same elements more than 1 times) in an array.So we have to count how many elements occured more than 1 time in the array. For ex: Consider the array [1,2,1,3,4,4,2] Here "1" is occuring 2 times and "2" is also occuring 2 times and "4"is also occuring 2 times.So the total number of elements is 3. So the output should be 3. Solution: When we take the input of elements in the array we put all the occuring elements in the hasmap or hashtable also parallely we will check if that particular element is occured previously or not,if occured we increment count value. Python Solution: n=int(input("Enter no. of elements")) a=[] hashmap=[] hashmap1=[] count=0 for i in range (0,n): ele=int(input()) if ele in hashmap and ele not in hashmap1: count=count+1 hashmap1.append(ele) ...