1 missed the 3 rd case (group three count)
According to the right answers, the test case of with n = 9 and if the array is 1 2 1 2 5 6 7 8 9 it gives 4 but it should 3, so, Please all check the problem, and help me.
The According to the right answer the tester is wrong then, if the size of the array is 9 and
the array is 1 2 1 2 5 6 7 8 9 the ans might 3 because change the height 5 to 6 and 7 and 8 to 9 but
in the right answer according to codechef, that comes 4 so i think it is a wrong qs
or say due to lack of attention by the tester
On test case 5 2 2 2 2 my code gives the answer 2. It’s supposed to be 1 though and my code got an AC in the contest.
@c_adept - the problem asks us to increase the height.
In this case - ‘2’ is the only student who is alone
We can take 1 student whose height is ‘1’ and make it ‘2’. The new heights will be 1 1 1 1 2 2 which will make all students happy.
yup, the test cases are incomplete…this same problem happened to me
How to see the failed test cases??
i didnt understand the last case , for odd numbers
Can you someone let me know what is test case number 5? Because I have all other test cases accepted, and I don’t know why test case 5 is failing.
Hey - @soniic99 - run your submission and when you get WA - click on ‘debug my code’ you will realize which test case your code failed on in this problem
Only one test Case is failing. Not getting what I have missed.
Problem Link :- CodeChef: Practical coding for everyone
{
ll n;
cin >> n;
vector<ll> v(n);
unordered_map<ll, ll> mp;
for ( ll i = 0 ; i < n ; i++)
{
cin >> v[i];
mp[v[i]]++;
}
debug(mp);
vector<ll> x;
for (auto it : mp)
{
if ( it.second == 1)
{
x.push_back(it.first);
}
}
int ans = 0;
if (x.size() == 0)
{
ans = 0;
}
else if ( x.size() == 1 )
{
ans = 1;
}
else if ( x.size() >= 4)
{
if ( x.size() % 2 == 0)
{
ans = x.size() / 2 ;
}
else
{
ans = ((x.size() +1) / 2) ;
}
}
else
{
ans = x.size() - 1 ;
}
cout << ans << "\n";
}
There is a special case when there is only one person with unique height, and if u see it was mentioned in the problem statement that we can only “increase” the height so we cannot change it to some lower value.
Consider the example n = 3 , A = [2 , 2 , 3]
Your code will output 1
correct answer is 2
I tried to do changes in my code according to your test case but still giving me wrong ans can u plz what changes should i do . and can u give me your discord or linkedin id
n = 6, A = [1 1 1 1 1 2]
Your Answer:
5
Correct Answer:
1
Reason: [1 1 1 1 2 2] is valid.
can u plz tell me what changes should i do in my code
you have to handle the edge case. The edge case being:
[1 1 2] => [2 2 2]
[1 1 2 2 3] => [1 1 3 3 3]
[1 1 2 2 3 3 4] => [1 1 2 2 4 4 4]
Meaning you have a list with the following properties:
1st: biggest element exists exactly once
2nd: all other elements exist EXACTLY twice
A way to do this is to add all elements to a map. Then ensure that the biggest element exists once and all other elements exactly twice. If that is the case, you print 2.
If this is not the case, you continue doing what you did before. Everything works, just not the edge case.
even after 2 years of your comment i did the same error lol.

