Problem 2: How to Reverse an Array with O(1) space and O(N) time

Problem 2: How to Reverse an Array without consuming any extra space and with O(N) time complexity

// we can do a Two pointer approach here. One Pointer starting from start and one at the end
int[] arr = new int[8];
arr[0] = 11;
arr[1] = 9;
arr[2] = 8;
arr[3] = 7;
arr[4] = 6;
arr[5] = -1;
arr[6] = 5;
arr[7] = -2;

int startIdx = 0; // as array starts from 0 idx
int endIdx = arr.length - ; // -1 because array start from 0 idx

// while startIdx < endIdx, we will swap the elements without wasting any space, and finally we will get the reversed array
while( startIdx < endIdx) {
    arr[startIdx] = arr[startIdx] + arr[endIdx];
    arr[endIdx] = arr[startIdx] - arr[endIdx];
    arr[startIdx] = arr[startIdx] - arr[endIdx];
}
return arr;