[C++] Check for each Query
Intuition\n Describe your first thoughts on how to solve this problem. \n- Check whether the sub-array (sequence) is arithmetic or not for each query\n\n# Appro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Check whether the sub-array (sequence) is arithmetic or not for each query\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Generate the sequence for each query\n- Sort and check the sequence\n\n# Complexity\n- Time complexity: $$O({m}\\times{n}\\times{\\log{n}})$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    // time/space: O(m * nlogn)/O(n)\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {\n        vector<bool> result(l.size());\n        for (int i = 0; i < l.size(); i++) {\n            vector<int> sequence(nums.begin() + l[i], nums.begin() + r[i] + 1);\n            result[i] = helper(sequence);\n        }\n        return result;\n    }\nprivate:\n    bool helper(vector<int>& s) {\n        sort(s.begin(), s.end());\n        for (int i = 0; (i + 1) < s.size(); i++) {\n            if ((s[i + 1] - s[i]) != (s[1] - s[0])) return false;\n        }\n        return true;\n    }\n};\n```
['Math', 'Sorting', 'C++']