📌📌C++/JAVA/Python3- Most intuitive, concise, and interview friendly code for beginners
Intuition\n\n For each query, bring out the required vector to check.\n sort the array for easy AP check\n If the size is less than two, then it is surely follo
# **Intuition**\n\n* For each query, bring out the required vector to check.\n* sort the array for easy AP check\n* If the size is less than two, then it is surely following AP.\n* else we\'ll check for all the values. If at any place it does not follow the progression, then it is not an AP following the sequence.\n\n--------------------------------------\n```Time complexity :``` **O(n*log(n))*** for sorting, and we are running the loop for m times, so overall time complexity will be ***O(n.m.log(n))*** \n# C++\n```\nclass Solution {\npublic:\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {\n        vector<bool> ans;\n        for(int i = 0; i < l.size(); i++){\n            vector<int> vec(nums.begin()+l[i], nums.begin()+r[i]+1);\n            sort(vec.begin(), vec.end());\n            \n            if(vec.size() < 2) ans.push_back(true);\n            else{\n                bool flag = true;\n                int diff = vec[1] - vec[0];\n                for(int j = 1; j < vec.size(); j++){\n                    if(vec[j] - vec[j-1] != diff) flag = false;\n                }\n                ans.push_back(flag);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n----------------------------------\n----------------------------------\n# Java\n```\nclass Solution {\n    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n        List<Boolean> ans = new ArrayList<>();\n        for (int i = 0; i < l.length; i++) {\n            int[] subArray = Arrays.copyOfRange(nums, l[i], r[i] + 1);\n            Arrays.sort(subArray);\n            \n            if (subArray.length < 2) {\n                ans.add(true);\n            } else {\n                boolean flag = true;\n                int diff = subArray[1] - subArray[0];\n                for (int j = 1; j < subArray.length; j++) {\n                    if (subArray[j] - subArray[j - 1] != diff) {\n                        flag = false;\n                        break;\n                    }\n                }\n                ans.add(flag);\n            }\n        }\n        return ans;\n    }\n}\n\n```\n----------------------------------------\n--------------------------------------------------------------------\n# Python3\n```\nclass Solution:\n    def checkArithmeticSubarrays(self, nums, l, r):\n        ans = []\n        for i in range(len(l)):\n            subArray = nums[l[i]:r[i] + 1]\n            subArray.sort()\n            \n            if len(subArray) < 2:\n                ans.append(True)\n            else:\n                flag = True\n                diff = subArray[1] - subArray[0]\n                for j in range(1, len(subArray)):\n                    if subArray[j] - subArray[j - 1] != diff:\n                        flag = False\n                        break\n                ans.append(flag)\n        return ans\n\n```
['C', 'Java', 'Python3']