Tap here to switch tabs
Problem
Submissions

Problem: Count Subarrays With Median K

Try to solve the Count Subarrays With Median K problem.

Statement

Given an integer array nums of size n containing distinct integers, and an integer k, return the number of non-empty subarrays that have a median equal to k.

The median of an array is the middle element after sorting its elements in non-decreasing order. If the array contains an even number of elements, the median is defined as the left middle element (the element located at index ⌊(m−1)/2⌋\lfloor (m - 1) / 2 \rfloor in the sorted array of length mm, assuming 00 based indexing).

Note: A subarray is a contiguous, non-empty sequence of elements within an array.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i], k ≤\leq n

  • All integers in nums are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Subarrays With Median K

Try to solve the Count Subarrays With Median K problem.

Statement

Given an integer array nums of size n containing distinct integers, and an integer k, return the number of non-empty subarrays that have a median equal to k.

The median of an array is the middle element after sorting its elements in non-decreasing order. If the array contains an even number of elements, the median is defined as the left middle element (the element located at index ⌊(m−1)/2⌋\lfloor (m - 1) / 2 \rfloor in the sorted array of length mm, assuming 00 based indexing).

Note: A subarray is a contiguous, non-empty sequence of elements within an array.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i], k ≤\leq n

  • All integers in nums are distinct.