Bheem has N friends. And he has a ladoo for each day. Given an Array A[] denoting on which day ith friend wants a ladoo. If Bheem is unable to give a ladoo to a friend, he loses his friendship with them. Find out the maximum number of Friends he can have at the end.
 
Example 1:
Input:
N = 5
A[] = {3, 3, 1, 2, 4}
Output:
4 
Explanation:
He will lose either his 1st or 2nd
friend and therefore will be left
with 4 friends.
Example 2:
Input:
N = 2
A[] = {1, 2}
Output:
2
Explanation:
He can give a ladoo to each of his friends,
and will have 2 friends by the end.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function divideLadoo() which takes an Integer N and an Array A as input and returns the answer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 <= N <= 10^{5}
1 <= A[i] <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def divideLadoo(self, N, A):

        # code here 

Solutions:
class Solution:

	def divideLadoo(self, N, A):
		return len(set(A))


class Solution:

	def divideLadoo(self, N, A):
		s = set()
		for i in A:
			s.add(i)
		return len(s)


from collections import Counter

class Solution:

	def divideLadoo(self, N, A):
		freq = Counter(A).values()
		ans = 0
		for i in freq:
			if i >= 1:
				ans += 1
		return ans


class Solution:

	def divideLadoo(self, N, A):
		return set(A).__len__()


class Solution:

	def divideLadoo(self, N: int, A: list) -> int:
		count = 0
		seen = set()
		for i in range(N):
			if A[i] not in seen:
				seen.add(A[i])
				count += 1
		return count


class Solution:

	def divideLadoo(self, N, A):
		dict = {}
		for i in A:
			if i in dict:
				dict[i] += 1
			else:
				dict[i] = 1
		return len(dict.keys())


class Solution:

	def divideLadoo(self, N, A):
		count = 0
		d = {}
		for i in A:
			if i not in d:
				d[i] = 1
				count += 1
			else:
				d[i] += 1
		return count


class Solution:

	def divideLadoo(self, N, A):
		d = {}
		for i in A:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		return len(d)


class Solution:

	def divideLadoo(self, N, a):
		return len(set(a))


class Solution:

	def divideLadoo(self, N, A):
		ht = {}
		for i in A:
			if i in ht:
				ht[i] += 1
			else:
				ht[i] = 1
		count = 0
		for key in ht.keys():
			count += 1
		return count


class Solution:

	def divideLadoo(self, N, A):
		hm = {}
		for i in range(N):
			if A[i] not in hm:
				hm[A[i]] = 1
			else:
				hm[A[i]] = hm[A[i]] + 1
		return len(hm)


class Solution:

	def divideLadoo(self, N, A):
		set1 = set(A)
		list2 = list(set1)
		return len(list2)


class Solution:

	def divideLadoo(self, N, A):
		r = set(A)
		return len(r)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		ob = Solution()
		print(ob.divideLadoo(N, A))


class Solution:

	def divideLadoo(self, N, A):
		h = {}
		for i in A:
			if i not in h:
				h[i] = 1
			else:
				h[i] += 1
		return len(h)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		ob = Solution()
		print(ob.divideLadoo(N, A))


class Solution:

	def divideLadoo(self, N, A):
		a = set(A)
		c = 0
		for i in a:
			c += 1
		return c


class Solution:

	def divideLadoo(self, N, A):
		d = {}
		c = 0
		for i in range(N):
			day = A[i]
			if day in d:
				c += 1
			else:
				d[day] = 1
		return N - c


class Solution:

	def divideLadoo(self, N, A):
		counter = {}
		for i in A:
			counter.setdefault(i, 0)
			counter[i] += 1
		return len(counter)


class Solution:

	def divideLadoo(self, N, A):
		B = {}
		for i in A:
			if i not in B.keys():
				B[i] = 1
		return len(B)