FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2751,3 "name": "sliding-subarray-beauty",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/sliding-subarray-beauty/",6 "date": "2023-04-16",7 "task_description": "Given an integer array `nums` containing `n` integers, find the **beauty** of each subarray of size `k`. The **beauty** of a subarray is the `xth`** smallest integer **in the subarray if it is **negative**, or `0` if there are fewer than `x` negative integers. Return _an integer array containing _`n - k + 1` _integers, which denote the _**beauty**_ of the subarrays **in order** from the first index in the array._ A subarray is a contiguous **non-empty** sequence of elements within an array. **Example 1:** ``` **Input:** nums = [1,-1,-3,-2,3], k = 3, x = 2 **Output:** [-1,-2,-2] **Explanation:** There are 3 subarrays with size k = 3. The first subarray is `[1, -1, -3]` and the 2nd smallest negative integer is -1. The second subarray is `[-1, -3, -2]` and the 2nd smallest negative integer is -2. The third subarray is `[-3, -2, 3] `and the 2nd smallest negative integer is -2. ``` **Example 2:** ``` **Input:** nums = [-1,-2,-3,-4,-5], k = 2, x = 2 **Output:** [-1,-2,-3,-4] **Explanation:** There are 4 subarrays with size k = 2. For `[-1, -2]`, the 2nd smallest negative integer is -1. For `[-2, -3]`, the 2nd smallest negative integer is -2. For `[-3, -4]`, the 2nd smallest negative integer is -3. For `[-4, -5]`, the 2nd smallest negative integer is -4. ``` **Example 3:** ``` **Input:** nums = [-3,1,2,-3,0,-3], k = 2, x = 1 **Output:** [-3,0,-3,-3,-3] **Explanation:** There are 5 subarrays with size k = 2**.** For `[-3, 1]`, the 1st smallest negative integer is -3. For `[1, 2]`, there is no negative integer so the beauty is 0. For `[2, -3]`, the 1st smallest negative integer is -3. For `[-3, 0]`, the 1st smallest negative integer is -3. For `[0, -3]`, the 1st smallest negative integer is -3. ``` **Constraints:** `n == nums.length ` `1 <= n <= 105` `1 <= k <= n` `1 <= x <= k ` `-50 <= nums[i] <= 50 `",8 "test_case": [9 {10 "label": "Example 1",11 "input": "nums = [1,-1,-3,-2,3], k = 3, x = 2",12 "output": "[-1,-2,-2] "13 },14 {15 "label": "Example 2",16 "input": "nums = [-1,-2,-3,-4,-5], k = 2, x = 2",17 "output": "[-1,-2,-3,-4] "18 },19 {20 "label": "Example 3",21 "input": "nums = [-3,1,2,-3,0,-3], k = 2, x = 1",22 "output": "[-3,0,-3,-3,-3] "23 }24 ],25 "constraints": [26 "A subarray is a contiguous non-empty sequence of elements within an array.",27 "n == nums.length",28 "1 <= n <= 105",29 "1 <= k <= n",30 "1 <= x <= k",31 "-50 <= nums[i] <= 50"32 ],33 "python_template": "class Solution(object):\n def getSubarrayBeauty(self, nums, k, x):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :type x: int\n :rtype: List[int]\n \"\"\"\n ",34 "java_template": "class Solution {\n public int[] getSubarrayBeauty(int[] nums, int k, int x) {\n \n }\n}",35 "metadata": {36 "func_name": "getSubarrayBeauty"37 }38}