#3739

Count Subarrays With Majority Element II

hard · 44.5% accepted · 62 likes · top 27%

array · hash table · divide and conquer · segment tree · merge sort · prefix sum

Description

You are given an integer array nums and an integer target.

Return the number of subarrays of nums in which target is the majority element.

The majority element of a subarray is the element that appears strictly more than half of the times in that subarray.

Solution