Could someone explain this code from editorial?


#1
int Solution::maxProfit(const vector<int> &arr) {
    int n = arr.size();
    if(n < 2) return 0;
    int s1 = arr[0], s2 = INT_MIN, s3 = INT_MIN, s4 = INT_MIN;
    for(int i = 1; i < n; i++) {
        s1 = min(s1, arr[i]);
        s2 = max(s2, arr[i]-s1);
        s3 = max(s3, s2-arr[i]);
        s4 = max(s4, s3+arr[i]);
    }
    return max(0, max(s2, s4));
}