Skip to content

Practice Sliding Subarray Beauty

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2653
LeetCode Problem

Sliding Subarray Beauty

Problem Statement

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.

Source: Sliding Subarray Beauty on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,-1,-3,-2,3], k = 3, x = 2
Output
[-1,-2,-2]

# Example 2

Input
nums = [-1,-2,-3,-4,-5], k = 2, x = 2
Output
[-1,-2,-3,-4]

# Example 3

Input
nums = [-3,1,2,-3,0,-3], k = 2, x = 1
Output
[-3,0,-3,-3,-3]

Constraints

n == nums.length
1 <= n <= 10^5
1 <= k <= n
1 <= x <= k
-50 <= nums[i] <= 50

Related LeetCode Problems

Practice more problems similar to Sliding Subarray Beauty.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.