Problem · Array
Compare Counts Around Pivot
Learn this problemProblem 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"ifcountGreateris greater thancountLess;"smaller"ifcountGreateris less thancountLess;"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) → StringExamples
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".