🦄 Simulate sequence with Set instead of sorting on JS / TS
Intuition\nThe common idea is that we don\'t need to sort subarrays. Instead, we can simulate same arithmetic sequence and check that every it\'s member exist i
# Intuition\nThe common idea is that we don\'t need to sort subarrays. Instead, we can simulate same arithmetic sequence and check that every it\'s member exist in subarray\n\n# Approach\n- Iterate over `l` and `r` pairs and create subarray `[nums[l], ..., nums[r]]`\n- Check is the subarray an arithmetic sequence:\n    - Get min and max values\n    - Get step between each member of it\n    - Create a `Set` from subarray values\n    - Simulate arithmetic sequence starting from `min` with given `steps`\n    - If every item of that sequence is exist in `Set`, then it is arithmetic sequence. \n\n# Complexity\n- Time complexity: $$O(n * m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n * m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```typescript []\nfunction checkArithmeticSubarrays(nums: number[], l: number[], r: number[]): boolean[] {\n    return l.map((_, i) => {\n        const subarray = nums.slice(l[i], r[i] + 1);\n\n        return isArithmeticSequence(subarray);\n    });\n}\n\nfunction isArithmeticSequence(nums: number[]): boolean {\n    const min = Math.min(...nums);\n    const max = Math.max(...nums);\n    const step = (max - min) / (nums.length - 1);\n\n    const set = new Set(nums);\n    return nums.every((_, i) => set.has(min + i * step))\n}\n```\n```javascript []\nfunction checkArithmeticSubarrays(nums, l, r) {\n    return l.map((_, i) => {\n        const subarray = nums.slice(l[i], r[i] + 1);\n\n        return isArithmeticSequence(subarray);\n    });\n}\n\nfunction isArithmeticSequence(nums) {\n    const min = Math.min(...nums);\n    const max = Math.max(...nums);\n    const step = (max - min) / (nums.length - 1);\n\n    const set = new Set(nums);\n    return nums.every((_, i) => set.has(min + i * step))\n}\n```
['TypeScript', 'JavaScript']