Sort and Check | Explained | Java | C++
Intuition and appraoch\nSince the input array size and the number of queries are of managable size.\nSo we can just store the elements included in the range of 
# Intuition and appraoch\nSince the input array size and the number of queries are of managable size.\nSo we can just store the elements included in the range of each query(left and right index bounds) and then sort that array and find out whether the array containing sorted elements of the current query is an A.P or not by checking the common diffrenece between two consecutive elements in the array.\n\n# Complexity\n- Time complexity:\nO(number of queries * max size of individual query * log(max size of individual query))\n\n- Space complexity:\nO(number of queries * max size of individual query), for making the sorted array for each incoming query\n\n# Code\nC++\n```\nclass Solution {\npublic:\n    vector<bool> checkArithmeticSubarrays(vector<int>& nums, vector<int>& l, vector<int>& r) {\n        int resultSize = l.size();\n        vector<bool> result(resultSize);\n          for(int resIndx = 0; resIndx < resultSize; resIndx++){ \n            int left = l[resIndx], right = r[resIndx];\n            vector<int> rArr;\n            for(int numsIndx = left; numsIndx <= right; numsIndx++){\n                rArr.push_back(nums[numsIndx]);\n            }\n            if(isArith(rArr)){\n                result[resIndx] = true;\n            }else{\n                result[resIndx] = false;\n            }\n          }  \n        return result; \n    }\nprivate:    \n    bool isArith(vector<int> & rArr){\n        sort(rArr.begin(), rArr.end());\n        int diff = rArr[1] - rArr[0];\n        for(int indx = 1; indx < rArr.size(); indx++){\n            if(diff != rArr[indx] - rArr[indx - 1]){\n                return false;\n            }\n        }\n        return true;    \n    }  \n};\n```\nJava\n```\nclass Solution {\n    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n        int resultSize = l.length;\n        List<Boolean> result = new ArrayList<>(resultSize);\n        for (int resIndx = 0; resIndx < resultSize; resIndx++) {\n            int left = l[resIndx], right = r[resIndx];\n            List<Integer> rArr = new ArrayList<>();\n            for (int numsIndx = left; numsIndx <= right; numsIndx++) {\n                rArr.add(nums[numsIndx]);\n            }\n            if (isArith(rArr)) {\n                result.add(true);\n            } else {\n                result.add(false);\n            }\n        }\n        return result;\n    }\n\n    private boolean isArith(List<Integer> rArr) {\n        Collections.sort(rArr);\n        int diff = rArr.get(1) - rArr.get(0);\n        for (int indx = 1; indx < rArr.size(); indx++) {\n            if (diff != rArr.get(indx) - rArr.get(indx - 1)) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n\n```
['C++', 'Java']