Since the array A has sufficient space for the merged array, we can start from the end of the array A and start filling the result elements.
We compare the elements at i and j indices. We move the bigger element to the end pointed by res and decrement the corresponding index. We do this until we reach the beginning of any array. Finally we check if there any left over elements in the second array. If there are, we have to move them to the first array.