Stretches With Median K
All items of nums are different, and k is one of them. The median of a stretch (one or more items next to each other) is its middle item once the stretch is sorted. A stretch of even length has two middle items, and its median is the smaller one.
Return how many stretches of nums have median k.
Example 1
nums [4,1,3,2,5]
k 3
returns 4
The stretches are [3], [4, 1, 3], [3, 2, 5] and the whole list.
Example 2
nums [1,2,3]
k 2
returns 3
The stretches are [2], [2, 3] and the whole list. In [1, 2] the smaller middle item is 1.
Constraints
1 <= len(nums) <= 300-109 <= nums[i] <= 109, all differentkis an item ofnums
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Hash maps problems
- Tiles That Make a RectangleHard
- Word Pairs That Make a MirrorHard
- Words Glued TogetherHard
- Already Seen FlagsBeginner
- Best Score per NameBeginner
- Check if the Sentence Is PangramBeginner
- Count Elements With a NextBeginner
- Difference of Two ArraysBeginner