@Pritamkumarcoder, since n can be as large as 10^7 so use scanf and print instead of cin and cout as scanf and print are faster for taking input , or if you want to use cin and cout then you can add these two lines below your in main() function
ios_base::sync_with_stdio(false);
cin.tie(NULL);
also in your code check for max frequency after if else condition , refer code below for better understanding
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.