Fazle the coolest boy is setting for a spacewalk along with his best friend Shaurya, However, he is worried that he would need cake as Shaurya's Birthday is near, he needs two cakes both of the same type of one for cutting the cake and another for cake-facial.
A number of cakes are ready at the shop with each type of cake denoted by a type T.
Fazle is in hurry and he is selecting the cakes randomly.
What is the Minimum Number of Cakes he has to select so that he can ensure he has at least two cakes of the same type for Shaurya's Birthday?
Example:
Input: n = 6, a = [1,2,1,2,3,5]
Output: 5
Approach
C++
#include <bits/stdc++.h>using namespace std;int spaceCakewalk(int n, int a[]){set<int> st;for (int i = 0; i < n; i++)st.insert(a[i]);int len = st.size();return len + 1;}int main(){int n = 6;int a[n] = {1, 2, 1, 2, 3, 5};cout << spaceCakewalk(n, a) << "\n";return 0;}
No comments:
Post a Comment