Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Given an array A[] of measurement N, and two integers Okay and C, the duty is to verify if all the weather of the array might be grouped into Okay teams such that every group has at most C components and all the weather of a gaggle are distinct.
Enter: N=6, A=[1, 2, 1, 2, 3, 4], Okay = 2, C=3
Output: Doable
Clarification: Let 2 teams be k1, k2 of capability 3.
If we put component with constructive integer 1, 2, 3 on group k1 i.e k1 have [1, 2, 3] and
if we put remaining 3 components 1, 2, 4 on group k2 i.e k2 have [1, 2, 4] then it attainable
to place all of the balls .Enter: N = 8, Balls = [1, 1, 1, 1, 1, 2, 2, 2], Okay = 2, C = 4
Output: Not possible
Clarification: It isn’t attainable to place the weather into
2 teams such that every group has all distinctive components
Method: The issue might be solved primarily based on the next thought:
Retailer the frequency depend of every component. If any component has frequency depend of greater than Okay then the reply can’t exist.
Comply with the steps talked about under to implement the concept.
Under is the Implementation of the strategy

Time Complexity: O(N log (N))
Auxiliary House: O(N)
The house requirement of the issue might be diminished. The array might be sorted so the frequency of every component might be counted with out the utilization of additional map as a result of they may all be current in consecutive indices.
Comply with the steps talked about under to implement the concept:
Under is the implementation of the above strategy

Time Complexity: O(N * logN) the time taken for sorting is O(N * logN)
Auxiliary House: O(1)