Tap here to switch tabs
Problem
Submissions

Problem: Count Subarrays With Majority Element I

Try to solve the Count Subarrays With Majority Element I problem.

Statement

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

An element is considered the majority element of a subarray of length kk if it appears strictly more than ⌊k/2⌋\lfloor k / 2 \rfloor times in that subarray.

Return the total number of contiguous non empty subarrays of nums in which target is the majority element.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq target ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Subarrays With Majority Element I

Try to solve the Count Subarrays With Majority Element I problem.

Statement

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

An element is considered the majority element of a subarray of length kk if it appears strictly more than ⌊k/2⌋\lfloor k / 2 \rfloor times in that subarray.

Return the total number of contiguous non empty subarrays of nums in which target is the majority element.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq target ≤109\leq 10^9