It’s unclear how function mergeSort is supported to operate, and what it returns. (Or if educative tracks some mutation or number of moves to measure “success”, as with Towers of Hanoi).
i looked at Java and saw void type for merge sort. So - how does a function recurse if there is no return data? (And no global structure).
A common approach is to make new sub-arrays, with array.splice(), like this:
Though space-intensive, the algorithm is very clear, and there is no need to pass around ints p, r, or q.
The description here makes it sound as if you are not actually dividing, just specifying smaller sub-arrays of the original structure.
I understand wanting to reduce space complexity, but the problem description needs to specify inputs, outputs, and success criteria.