I am unable to solve this question using O(1) space complexity

I haven’t seen the video explanations yet but trying to solve questions on my own. I am failing in 2 test cases in this question . Here is my solution. What’s wrong and how can I optimize my solution?https://ide.codingblocks.com/s/596489

hi… u are restricting the array size to 1001 but according to constraints 0<=Ai<=10^9…
so u have to correct it… u can use a map for this…
refer this https://ide.codingblocks.com/s/596610

Hi, thanks for the answer, Now its passing 5 test cases and failing in 1 private test case? I couldn’t figure out why it’s failing .Can you help me out !

Hi… can u tell me what error u are getting on last test case… bcoz code seems fine now…

Wrong answer on one of the test case, I have copied the same code but for 1 test case its giving me WA. I dont know the input of it because it’s a pvt. test case

ok… let me see…

hi… i have tried on all sample test cases… it is working fine… there may be some compiler issues thats why u are getting the error… dont worry and just move ahead with other questions…

Yeah Okay! using majority vote for this problem as discussed in the video is efficient or this approach? Which is better to use

that approach solves it in O(1)… and the above approach uses O(N) space… so ya majority vote is an optimized one… u can try with that also…

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.