Swap and Maximize | GFG POTD | 1-11-24 | Easy Level | GFG Problem of the day | 3 Lines of Code

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 1

  • @codewithuday
    @codewithuday  23 дня назад +1

    class Solution {
    public:
    long long maxSum(vector& arr) {
    // code here
    sort(arr.begin(),arr.end());
    int n = arr.size();
    long long int diff = 0;
    for(int i =0;i R || R -> L
    diff += (2*(arr[n-1-i] - arr[i]));
    }
    return diff;
    }
    };