We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your solution is O(NlogN) due to having to sort the array. The editorial solution avoids sorting, at the cost of a constant-sized array (size related to one of the problem's constant parameters; call it M, so that solution is O(N)+O(M).
The editorial solution is pretty much the same as yours, except without having to sort the array; instead doing the first part (loop on N) that more or less has the same effect as sorting for the purposes of this problem. I don't want to go into too much detail here.
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
Your solution is O(NlogN) due to having to sort the array. The editorial solution avoids sorting, at the cost of a constant-sized array (size related to one of the problem's constant parameters; call it M, so that solution is O(N)+O(M).
The editorial solution is pretty much the same as yours, except without having to sort the array; instead doing the first part (loop on N) that more or less has the same effect as sorting for the purposes of this problem. I don't want to go into too much detail here.