testcases are not passing, showing that code is slow
How to optimize this code?
Your algorithm was correct. But the test cases were really tight. It usually does not happen in actual coding challenges/contests.
I have made some changes in your code. like changing endl to “\n”, flushing the cin and cout, and sync with stdio(false).
@uthyasani
can you please explain why ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
these lines are used to reduce time complexity?
These do not affect the time complexity of the code. But it fastens the input output process for the code which further Reduces the run time of the code. For further understanding, please do give this article a read https://www.google.com/amp/s/www.geeksforgeeks.org/fast-io-for-competitive-programming/amp/
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.