Arithmetic Subarrays Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the subarrays and check for the diff. If the diff is same for all elements in the 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the subarrays and check for the diff. If the diff is same for all elements in the sub array then push True, else false.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Make a temp vector and a boolean vector ans.\n2. Traverse the \'l\' vector and make subarrays in range l[i] and r[i] ans store in the temp array.\n3. Sort this temp array.\n4. Check if the difference is same for all elements in this subarray.\n5. If all differences are same, then push \'true\' in ans vector else \'false\'.\n6. Return ans vector.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n^2logn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution {\npublic:\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {\n        int i, j, diff, flag;\n        vector<int> temp;\n        vector<bool> ans;\n        for(i=0 ; i<l.size() ; i++)\n        {\n            temp.insert(temp.begin(), nums.begin()+l[i], nums.begin()+r[i]+1);\n            sort(temp.begin(), temp.end());\n            diff = temp[1]-temp[0];\n\n            for(j=2 ; j<temp.size() ; j++)\n            {\n                if(temp[j]-temp[j-1]!=diff)\n                {\n                    break;\n                }\n            }\n            if(j==temp.size())\n            {\n                ans.push_back(true);\n            }\n            else\n            {\n                ans.push_back(false);\n            }\n            temp.clear();\n        }\n        return ans;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/a4090849-8a64-49ae-ba02-5f4d159f4154_1682613128.9648194.jpeg)\n
['C++']