703454. Surpasser Count

Medium

Surpasser Count

Summary

The Surpasser Count problem involves finding the number of elements in an array that are greater than a given element. This problem requires understanding basic array manipulation and comparison techniques.

Detailed Explanation

To solve this problem, we can iterate through the array and count the number of elements that are greater than the given element. We start by initializing a counter to zero. Then, for each element in the array, we compare it with the given element. If the current element is greater, we increment the counter.

Here's the step-by-step breakdown:

  1. Initialize a counter count to 0.
  2. Iterate through the array from left to right.
  3. For each element arr[i], compare it with the given element target.
  4. If arr[i] > target, increment the count variable by 1.
  5. Return the final value of count.

Time complexity: O(n), where n is the length of the array, since we're iterating through the array once.

Space complexity: O(1), as we're not using any additional space that scales with the input size.

Optimized Solutions

Java

View on GeeksforGeeks
public int surpasserCount(int[] arr, int target) {
    int count = 0;
    for (int i = 0; i < arr.length; i++) {
        if (arr[i] > target) {
            count++;
        }
    }
    return count;
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.