Search
⌘K

Leetcode 2488. Count Subarrays With Median K

Count how many contiguous subarrays of a distinct-integer array have median equal to k (median is the middle element, or the left-middle for even lengths). The core challenge is to do this efficiently (n up to 1e5) by reducing elements to >k / <k and using prefix-sum counts or a hashmap to count qualifying subarrays.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.