Q1 is a simple greedy algorithm in which you just need to find the sum of absolute difference of adjascent elements.
Code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int sum=0;
for(int i=n-1;i>=1;i--)
sum+=abs(arr[i]-arr[i-1]);
cout<<sum<<endl;
return 0;
}