Cyclically rotate an array by one

1 min read

https://practice.geeksforgeeks.org/problems/cyclically-rotate-an-array-by-one/0

Also works for rotation by N elements

void reverseArr(int arr[], int r) {
  for (int i = 0; i < r / 2; i++) {
    int tmp = arr[i];
    arr[i] = arr[r - i - 1];
    arr[r - i - 1] = tmp;
  }
}
void rotate(int arr[], int n) {
  reverseArr(arr, n - 1);
  reverseArr(arr, n);
}
Find the union and intersection of the two sorted arrays
Minimise the maximum difference between heights