I am getting TLE. How can I optimize the solution ?
IDE : https://ide.codingblocks.com/s/196465
Busy Man - SPOJ
Hi @aman_ishan
For sorting you can use merge sort as it has complexity of nlogn whereas you are using bubble sort which is O(n^2) hence it times out.
Hope it Helps.
But in merge sort how will i change both the arrays simultaneously ?
Hi @aman_ishan
I dont know much about java but it can be implemented in c++ using vector of pairs and sorting that vector. I guess pairs exist in java too.
Hope it Helps.
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.