EASY JAVA APPROACH for Beginners !
Intuition\n- For every possible subarray in the rangel[i] to r[i] check if it is an AP or not.\n- A sequence is said to be in AP if the difference between it\'s
# Intuition\n- For every possible subarray in the range`l[i] to r[i]` check if it is an AP or not.\n- A sequence is said to be in AP if the difference between it\'s **consecutive** terms remain constant/equal.\n\n# Approach\n1. Take m queries one by one.\n2. Create an array **arr** of size` r[i]-l[i]+1` to store the elements in range `l[i] to r[i]` both inclusive\n3. store values from index `l[i] to r[i]` in the array **arr**\n4. Sort the array as the rearrangement after sorting is also an AP\n5. Initialize the common difference `d=arr[1]-arr[0]`\n6. Check if all possible pairs have the same common difference `d` .If all the differences are equal then add True to the final list otherwise False.\n\n# Complexity\n- Time complexity: **$$O(M\u2217N\u2217Log(N))$$**\n\n- Space complexity:**$$O(N)$$**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n        int n=nums.length;\n        int m=l.length;\n        \n        List<Boolean>list=new ArrayList<>();\n        for(int i=0;i<m;i++){\n            int k=0;\n            int arr[]=new int[r[i]-l[i]+1];\n            for(int j=l[i];j<=r[i];j++){\n                arr[k]=nums[j];\n                k++;\n            }\n            Arrays.sort(arr);\n            boolean ans=true;\n            int d=arr[1]-arr[0];\n            for(int s=2;s<arr.length;s++){\n                if(arr[s]-arr[s-1]!=d)\n                    ans=false;\n            }\n            list.add(ans);\n\n        }\n        return list;\n    }\n}\n```
['Array', 'Sorting', 'Java']