Simplest and best solution(easy to understand)|| C++ || Array || Sorting
Intuition\nThe problem requires checking if specific subarrays of a given array nums form an arithmetic sequence. An arithmetic sequence has a constant differen
# Intuition\nThe problem requires checking if specific subarrays of a given array nums form an arithmetic sequence. An arithmetic sequence has a constant difference between consecutive elements. For each query, we need to extract the specified subarray, sort it, and check if the differences between consecutive elements are equal.\n\n# Approach\nLoop Through Each Query: For each query, use indices l[i] and r[i] to define the start and end of the subarray.\nExtract and Sort Subarray: Extract the subarray using the range from l[i] to r[i], then sort it to ensure we can easily check if it forms an arithmetic sequence.\nCheck Arithmetic Property: Calculate the common difference between the first two elements of the sorted subarray. Traverse the rest of the elements to check if each consecutive difference matches the initial difference.\nStore the Result: If all consecutive differences match, the subarray is arithmetic, so append true to result; otherwise, append false.\n\n# Complexity\n- Time complexity:\nTime Complexity: \nO(m.nlogn)\n\n- Space complexity:\nO(m)\n\n# Code\n```cpp []\n\nclass Solution {\npublic:\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l,\n                                          vector<int>& r) {\n        int queryCount = l.size();\n        vector<bool> result;\n\n        for (int i = 0; i < queryCount; i++) {\n\n            vector<int> subarray(nums.begin() + l[i], nums.begin() + r[i] + 1);\n            sort(subarray.begin(), subarray.end());\n\n            int n = subarray.size();\n            bool isArithmetic = true;\n\n            if (n < 2) {\n                result.push_back(false);\n                continue;\n            }\n\n            int difference = subarray[1] - subarray[0];\n\n            for (int j = 1; j < n - 1; j++) {\n                if (subarray[j + 1] - subarray[j] != difference) {\n                    isArithmetic = false;\n                    break;\n                }\n            }\n            result.push_back(isArithmetic);\n        }\n\n        return result;\n    }\n};\n```
['Array', 'Sorting', 'C++']