Tap here to switch tabs
Problem
Submissions

Problem: Minimum Index of a Valid Split

Minimum Index of a Valid Split asks you to find the first index dividing an integer array into two parts where one value appears more than half the time in each, or return negative one if none exists.

Statement

An element xx of an integer array arr of length mm is considered dominant if its frequency satisfies freq(x)×2>m\text{freq}(x) \times 2 > m, where freq(x)\text{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...i] and nums[i + 1...n - 1], where 0≤0 \leq i <n−1< n - 1. The split is considered valid if both subarrays nums[0...i] and nums[i + 1...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

Minimum Index of a Valid Split asks you to find the first index dividing an integer array into two parts where one value appears more than half the time in each, or return negative one if none exists.

Statement

An element xx of an integer array arr of length mm is considered dominant if its frequency satisfies freq(x)×2>m\text{freq}(x) \times 2 > m, where freq(x)\text{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...i] and nums[i + 1...n - 1], where 0≤0 \leq i <n−1< n - 1. The split is considered valid if both subarrays nums[0...i] and nums[i + 1...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.