Here is my solution. It uses Merge Sort but it still gived TLE :frowning:
Any help would be appreciated. Please don’t provide solutions using BIT or Segment Tree. How can I optimize my solution using Merge Sort method ?
Thanks in advance.
Here is the link to my solution:

Just remove unnecessary modulo operations :slight_smile: Your slightly edited submission. In merge function there is no need to take values of array result by modulo, since they are at most N - 1.

1 Like

Thanks eartemov .
You are a life saver.