Please tell me the error in my code

code-https://ide.codingblocks.com/s/331193
The code is going into a segmentation fault.

@amanb25
Will revert to you ASAP.

@amanb25
There were many errors in your code.

  1. you didn’t pass the parameters correctly to the merge function.
  2. You set the array size before taking the size of the array as input.
  3. In the merge function, when we exit out of the first while loop, you performed a mistake with the condition while(i <= s) , it should have been while(i <= mid).
  4. When arr[i] < arr[j], you do not add arr[i] to the answer, you add arr[i]*(e - j + 1) to the answer because the arr[i] element should be included in the alpha scores of all elements from j to e.

This is the updated code.

If you face any issues, feel free to revert.
If my answer was able to answer your issues, please mark the doubt as resolved.

Helo, yea hi understood and tried your code. However, it still isn’t passing all test cases, it gives TLE in 2 and wrong answer for 1.

even after i increase the size of the array it gives wrong answer for 2

@amanb25
You directly used the above one? I have made the arr2 a global variable. I set its size to 100 because I was debugging the code. You set its size to the desired one. It should work the.

yes i changed the size to 1000000. Stil doesn’t work

@amanb25
Did you take modulus wrt 1e9 + 7? Because that has been asked for in the question.