Java without using sort with explanation.
\nUse the concept of AP(arithmetic progression)\nnth term = a+(n-1)*d\n\nclass Solution {\n\n  public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l
\nUse the concept of AP(arithmetic progression)\n`nth term = a+(n-1)*d`\n```\nclass Solution {\n\n  public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n        List<Boolean> res = new ArrayList<Boolean>();\n        for(int i = 0; i < l.length; i++) {\n            res.add(isArithmeticSeq(nums, l[i], r[i]));\n        }\n        \n        return res;\n    }\n    \n    private boolean isArithmeticSeq(int[] nums, int start, int end) {\n        \n      // if there are 0, 1 or only 2 elements in that subarray then no need to check further. They will be in arithmetic progression(AP)\n        if(end - start < 2) return true;\n        \n        \n        // We know the formula for finding the nth term i.e  nth term = a + (n-1)*d\n        // a is starting element and d is difference in AP.\n        // Consider the nth term to be the last and a is starting, this will make last term maximum and starting minimum in AP if diff is positive\n        //By following this rule we can say that  max = min +(noOfElements-1)*d;\n        //Which is nothing but max = min*(end-start)*d;\n        // (max - min)/(end-start) = d;\n        // So to find the difference we find max and min while putting those elements in the set to check them later..\n        int min=Integer.MAX_VALUE, max=Integer.MIN_VALUE;\n        Set<Integer> set = new HashSet<Integer>();\n        for(int i = start; i <= end; i++) {\n            min = Math.min(min, nums[i]);\n            max = Math.max(max, nums[i]);\n            set.add(nums[i]);\n        }\n        \n        // now we will check whether AP is possible or not..\n        // for eg [2,4,5,7] => (7-2)/3  = 5/3 i.e 3 can not completely divide 5, so we can say that. a number 7 can not be made by  starting from 2 if there are only 3 increments possible, So we return false;\n        if((max - min) % (end - start) != 0) return false;\n        \n        //As derived above we find difference using this formula\n        int diff = (max - min) / (end -start);\n        \n        //Now we will check wheather all elements in the subarray can be built by using a+(n-1)*d i.e min+i*diff\n        // and if that element is not found in the set that we previously created then return false;\n        for(int i = 1; i <= end -start; i++) {\n            if(!set.contains(min + i * diff)) return false;\n        }\n        //if all elements are present in the set then return true;\n        return true;\n    }\n}\n```\n
['Ordered Set', 'Java']