One test case is failing for Majority Element problem. Not able to figure out the case where this is exactly failing.
Where can we share the code for the same?
One test case is failing for Majority Element problem. Not able to figure out the case where this is exactly failing.
Where can we share the code for the same?
If an array contains 0 as majority element , then I guess there is an issue as by default int array has all elements as 0.
Suggest what to do in such a case.
yeah u r right ,that is the issue initialise ur second variable with -1 .
I don’t think this will solve the problem
it will work.
other mistakes.
the way u are checking whether res is empty or not is not correct.
u can check it like ->if k==0 then res is empty
also u have declared res of size 2 , so u will always print 2 elements in ur output.
but only element is also possible in output.
We need to initialize the array while creating it, so did it.
Added k==0 condition and applied one condition while printing the elements. Now it is working fine.
But if -ve values are allowed then need to think of some alternative.
Thanks 
for this problem only non negative numbers are allowed.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.