[Java] O(NM) Math Solution: Building The Sequence Yourself
I\'ll admit. This solution will probably took me a lot of time to come up with during the contest. However, since the problem can be brute-forced, I didn\'t was
I\'ll admit. This solution will probably took me a lot of time to come up with during the contest. However, since the problem can be brute-forced, I didn\'t waste any time. Enjoy! :)\n```\nclass Solution {\n    public List<Boolean> checkArithmeticSubarrays(int[] nums, int[] l, int[] r) {\n        List<Boolean> res = new ArrayList<>();\n        int n = l.length;\n        for (int i = 0; i < n; i++) {\n            res.add(check(Arrays.copyOfRange(nums, l[i], r[i] + 1)));\n        }\n        return res;\n    }\n    \n    private boolean check(int[] subarr) {\n        if (subarr.length < 2) {\n            return false;\n        }\n        int n = subarr.length;\n        int min = subarr[0];\n        int max = subarr[0];\n        Set<Integer> elements = new HashSet<>();\n        elements.add(subarr[0]);\n        for (int i = 1; i < n; i++) {\n            min = Math.min(min, subarr[i]);\n            max = Math.max(max, subarr[i]);\n            elements.add(subarr[i]);\n        }\n        int sum = max - min;\n        if (sum % (n - 1) != 0) {\n            return false;\n        }\n        int gap = sum / (n - 1);\n        int cur = min;\n        for (int i = 0; i < n; i++) {\n            if (!elements.contains(cur)) {\n                return false;\n            }\n            cur += gap;\n        }\n        return true;\n    }\n}\n```
[]