java.lang.Object
g2601_2700.s2653_sliding_subarray_beauty.Solution

public class Solution extends Object
2653 - Sliding Subarray Beauty.<p>Medium</p> <p>Given an integer array <code>nums</code> containing <code>n</code> integers, find the <strong>beauty</strong> of each subarray of size <code>k</code>.</p> <p>The <strong>beauty</strong> of a subarray is the <code>x<sup>th</sup></code> <strong>smallest integer</strong> in the subarray if it is <strong>negative</strong> , or <code>0</code> if there are fewer than <code>x</code> negative integers.</p> <p>Return <em>an integer array containing</em> <code>n - k + 1</code> <em>integers, which denote the</em> <strong>beauty</strong> <em>of the subarrays <strong>in order</strong> from the first index in the array.</em></p> <ul> <li>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,-1,-3,-2,3], k = 3, x = 2</p> <p><strong>Output:</strong> [-1,-2,-2]</p> <p><strong>Explanation:</strong> There are 3 subarrays with size k = 3.</p> <p>The first subarray is <code>[1, -1, -3]</code> and the 2<sup>nd</sup> smallest negative integer is -1.</p> <p>The second subarray is <code>[-1, -3, -2]</code> and the 2<sup>nd</sup> smallest negative integer is -2.</p> <p>The third subarray is <code>[-3, -2, 3]</code>and the 2<sup>nd</sup> smallest negative integer is -2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [-1,-2,-3,-4,-5], k = 2, x = 2</p> <p><strong>Output:</strong> [-1,-2,-3,-4]</p> <p><strong>Explanation:</strong> There are 4 subarrays with size k = 2.</p> <p>For <code>[-1, -2]</code>, the 2<sup>nd</sup> smallest negative integer is -1.</p> <p>For <code>[-2, -3]</code>, the 2<sup>nd</sup> smallest negative integer is -2.</p> <p>For <code>[-3, -4]</code>, the 2<sup>nd</sup> smallest negative integer is -3.</p> <p>For <code>[-4, -5]</code>, the 2<sup>nd</sup> smallest negative integer is -4.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [-3,1,2,-3,0,-3], k = 2, x = 1</p> <p><strong>Output:</strong> [-3,0,-3,-3,-3]</p> <p><strong>Explanation:</strong> There are 5 subarrays with size k = 2**.**</p> <p>For <code>[-3, 1]</code>, the 1<sup>st</sup> smallest negative integer is -3.</p> <p>For <code>[1, 2]</code>, there is no negative integer so the beauty is 0.</p> <p>For <code>[2, -3]</code>, the 1<sup>st</sup> smallest negative integer is -3.</p> <p>For <code>[-3, 0]</code>, the 1<sup>st</sup> smallest negative integer is -3.</p> <p>For <code>[0, -3]</code>, the 1<sup>st</sup> smallest negative integer is -3.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == nums.length</code></li> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>1 <= k <= n</code></li> <li><code>1 <= x <= k</code></li> <li><code>-50 <= nums[i] <= 50</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • getSubarrayBeauty

      public int[] getSubarrayBeauty(int[] nums, int k, int x)