Element Appearing More Than 25% In Sorted Array

71.0% Acceptance

In this lab, you will be solving a problem in which you have to find the element that appears more than 25% of the time in a sorted array. The given integer array is sorted in non-decreasing order, and there is exactly one integer in the array that occurs more than 25% of the time. Your task is to write a function that returns that integer.

For example, consider the following cases:

Example 1:

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

Example 2:

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

Remember the following constraints as you develop your solution:

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

The lab has several challenges to help you practice and test your implementation. These challenges are designed to cover different aspects of the problem and ensure that your solution is correct and efficient. The challenges are as follows:

  1. Write the function findSpecialInteger that takes an array as input and returns the integer that appears more than 25% of the time in the array.
  2. Export the findSpecialInteger function so that it can be tested in the evaluation script.
  3. Ensure that your function has the correct time complexity for optimal performance.

The evaluation script will test your implementation against these challenges to ensure correctness and efficiency. Make sure to export any functions or variables you are using in the challenges so that the evaluation script can test them properly.

Note that you must use ESM import/export syntax everywhere in your implementation. Also, follow all rules and guidelines mentioned above while building the lab, especially those related to the evaluation script.

Good luck, and happy coding!