Problem
Chef has an array of length .
In one operation, Chef can remove any one element from the array.
Determine the minimum number of operations required to make all the elements same.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer —the length of Array .
- Next line contains space-separated integers - denoting the array .
Output Format
For each test case, output the minimum number of operations required to make all the elements same.
Constraints
- Sum of over all test cases do not exceed
Sample 1:
Input
Output
4 3 3 3 3 6 1 3 2 1 2 2 4 1 2 1 2 5 1 3 2 4 5
0 3 2 4
Explanation:
Test case : All the elements are already same. Thus we need to perform zero operations.
Test case : We remove the elements and using three operations. The array becomes where all elements are same.
Test case : We remove the elements and using two operations. The array becomes where all elements are same.
Test case : We remove the elements and using four operations. The array becomes .
Solution:-
def count(arr,n):
d=dict()
for i in range(n):
if arr[i] in d.keys():
d[arr[i]]+=1
else:
d[arr[i]]=1
a=max(d.values())
print(n-a)
t=int(input())
for i in range(t):
n=int(input())
a=list(map(int,input().split()))
count(a,len(a))
Companies interview:-
- Swap adjacent characters
- Double the vowel characters
- Check valid parenthesis
- Print the characters with their frequencies
- Find closest value
- Word Count
- Program of CaesarCipher
- Program to find the perfect city
- Annual Day | Tech Mahindra coding question
- Find the number of pairs in the array whose sum is equal to a given target.
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
See more:-
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
aaaaa
0 Comments