Element Appearing More Than 25% In Sorted Array

Easy
1
53.3% Acceptance

In this lab, your task is to implement a function that finds the element that appears more than 25% of the time in a given sorted integer array. The input array will be sorted in non-decreasing order, and there will be exactly one such element in the array. Your function should return the value of this element.

Function signature:

/** * @param {number[]} arr * @return {number} */ var findSpecialInteger = function(arr) { };

Examples

Example 1:

Input: arr = [1,2,2,6,6,6,6,7,10] Output: 6

Example 2:

Input: arr = [1,1] Output: 1

Constraints:

  • 1 <= arr.length <= 104
  • 0 <= arr[i] <= 105

Challenges

  1. Export the findSpecialInteger function.
  2. Implement the function findSpecialInteger correctly.
  3. Function should pass the given test cases.