## Problem https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/description/ <br> :::spoiler **Optimal Space & Time Complexity** ``` - Time complexity: - Space complexity: ``` ::: <br> <hr/> ## Solutions :::spoiler 東 ```javascript= ``` ::: <br> :::spoiler Hao ```javascript= ``` ::: <br> :::spoiler YC ```javascript= ``` ::: <br> :::spoiler SOL ```javascript= ``` ::: --- ## Supplement / Discussion ### 東 ### Hao 1. Line Sweep Algorithm - [Solution](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/solutions/3788266/using-maximum-number-of-overlapping-intervals-approach/) <br /> 2. Sliding Window - [Explaination](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/solutions/3772327/why-and-how-of-the-solution/) - [Solution](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/solutions/3771237/javascript-sliding-window-sorting/) ```javascript= var maximumBeauty = function(nums, k) { nums.sort((a, b) => a - b); let ans = 0, n = nums.length; for (let j = 0, i = 0; j < n; j++) { while (nums[j] - nums[i] > k * 2) i++; // - the same: while (nums[j] - k > nums[i] + k) i++; // - i, j are indexs where i <= j // - once the minumum of the range of nums[j] is still greater than the maximum of the range of nums[i], // - it means these two number have no overlaps. ans = Math.max(ans, j - i + 1); } return ans; }; ``` ### YC ### SOL