Problem · Array

Compare Counts Around Pivot

Learn this problem
EasyCapital One logoCapital OneINTERNOA

Problem statement

You are given an array of integers numbers and an integer pivot. Let countGreater denote how many integers within numbers are strictly greater than pivot, and countLess denote how many integers are strictly less than pivot.

Your task is to compute countGreater and countLess, then return:

  • "greater" if countGreater is greater than countLess;
  • "smaller" if countGreater is less than countLess;
  • "tie" if they are equal.

Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(numbers.length^2) will fit within the execution time limit.

Function

solution(numbers: int[], pivot: int) → String

Examples

Example 1

numbers = [1, 3, 0, -1, 1, 4, 3]pivot = 2return = "smaller"

There are countGreater = 3 integers greater than pivot = 2. The integers less than 2 are 1, 0, -1, and 1, so countLess = 4. Since countGreater is less than countLess, the result is "smaller".

More Capital One problems

drafts saved locally
public String solution(int[] numbers, int pivot) {
  // write your code here
}
numbers[1, 3, 0, -1, 1, 4, 3]
pivot2
expected"smaller"
checking account