Discover Financial Services Hiring | Count Subarrays With Median K | off campus 2024

Question · Posted Jun 2026

Problem Statement You are given an array nums of size n consisting of distinct integers from 1 to n and a positive integer k. Return the number of non-empty subarrays in nums that have a median equal to k. Note: The median of an array is the middle element after sorting the array in ascending order. If the array is of even length, the median is the left middle element. For example, the median of [2,3,1,4] is 2, and the ...

The full answer & interview discussion are available to premium members.

Log in Create a free account