0

Print the minimum number of deletion operations required to make a list as equal

python

16th Aug 2017, 10:15 AM
Akilan
Akilan - avatar
3 ответов
0
please be more clear....explain your question with an example
16th Aug 2017, 5:19 PM
Rishi Anand
Rishi Anand - avatar
0
Input Format: The first line contains N denote the numbers of elements in list. The next line contains a list of N numbers Output Format: Print the minimum number of deletion operations required to make a list as equal. Sample Input: 5 3 3 2 1 3 Sample Output: 2 Explanation: If we delete 2,1 the list will become [3,3,3].So we need two delete operations required to make a list equal
17th Aug 2017, 3:41 AM
Akilan
Akilan - avatar
0
OK...got it suppose n is the length of list the algorithm is like first you need to count the frequency of the most frequent element in the list(say freq) and then in order to get the answer you just need to do (n-freq) import sys n=eval(input())#number of elements lst1=list(map(int,input().split()))#creating a list l=len(lst1)#list length if(n!=l): sys.exit() #extracing the unique elements from lst1 lst2=[] for i in range(0,l): if(lst1[i] in lst2): continue else: lst2.append(lst1[i]) #finding the frequency of the most frequent #element of lst1 big=0 for i in range(0,len(lst2)): c=0 for j in range(0,l): if(lst2[i]==lst1[j]): c+=1 if(c>big): big=c #required answer print(l-big) hope this will be helpful
17th Aug 2017, 10:48 AM
Rishi Anand
Rishi Anand - avatar