Tap here to switch tabs
Problem
Submissions

Problem: Minimum Index of a Valid Split

Try to solve the Minimum Index of a Valid Split problem.

Statement

An element xx of an integer array arr of length mm is considered dominant if its frequency satisfies $ ext{freq}(x) imes 2 > m$, where $ ext{freq}(x)$ is the number of occurrences of xx in arr.

You are given a 00 indexed integer array nums of length nn that contains exactly 11 dominant element.

A split at index i divides nums into two contiguous subarrays: nums[0 \dots i] and nums[i + 1 \dots n - 1], where 0≤0 \leq i <n−1< n - 1. The split is considered valid if both subarrays nums[0 \dots i] and nums[i + 1 \dots n - 1] have the same dominant element as nums.

Return the minimum index i of a valid split. If no valid split exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

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

  • nums has exactly 11 dominant element.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Index of a Valid Split

Try to solve the Minimum Index of a Valid Split problem.

Statement

An element xx of an integer array arr of length mm is considered dominant if its frequency satisfies $ ext{freq}(x) imes 2 > m$, where $ ext{freq}(x)$ is the number of occurrences of xx in arr.

You are given a 00 indexed integer array nums of length nn that contains exactly 11 dominant element.

A split at index i divides nums into two contiguous subarrays: nums[0 \dots i] and nums[i + 1 \dots n - 1], where 0≤0 \leq i <n−1< n - 1. The split is considered valid if both subarrays nums[0 \dots i] and nums[i + 1 \dots n - 1] have the same dominant element as nums.

Return the minimum index i of a valid split. If no valid split exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

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

  • nums has exactly 11 dominant element.