Best solution for java || beats 100% || T.C = m*(n+n)
\n\n# Complexity\n- Time complexity: (m*(n+n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(
\n\n# Complexity\n- Time complexity: (m*(n+n))\n<!-- Add your time complexity here, e.g. $$O(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        List<Boolean> ans=new ArrayList<>();\n        for(int i=0;i<l.length;i++){\n            int st=l[i];\n            int end=r[i];\n            if(solve(nums,st,end)){\n                ans.add(true);\n            } else {\n                ans.add(false);\n            }\n        }\n        return ans;\n    }\n    public boolean solve(int arr[],int l,int r){\n        int len=r-l+1;\n        int min=Integer.MAX_VALUE;\n        int max=Integer.MIN_VALUE;\n        for(int i=l;i<=r;i++){\n            min=Math.min(min,arr[i]);\n            max=Math.max(max,arr[i]);\n        }\n        int diff=max-min;\n        if(diff==0){\n            return true;\n        }\n        if(diff % (len-1)!=0){\n            return false;\n        }\n        diff=diff/(len-1);\n        boolean visited[]=new boolean[len];\n        for(int i=l;i<=r;i++){\n            if((arr[i]-min)%diff!=0){\n                return false;\n            }\n            int pos=(arr[i]-min)/diff;\n            if(visited[pos]){\n                return false;\n            }\n            visited[pos]=true;\n        }\n        return true;\n    }\n}\n```
['Math', 'Java']