Problem · Array
Compare Counts Around Pivot
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.
Examples
01 · Example 1
numbers = [1, 3, 0, -1, 1, 4, 3] pivot = 2 return = "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
- Reconstruct Landmark JourneyOA · Seen Jun 2026
- Count House Segments After DestructionOA · Seen May 2026
- Count Numbers with Even Number of DigitsOA · Seen May 2026
- Laser Robot Safe PathOA · Seen May 2026
- Longest Same-Character SubstringOA · Seen May 2026
- Cyclic Shift to Strictly Descending ArrayOA · Seen May 2026
- Dynamic Wall Building and Range QueryOA · Seen May 2026
- Queue Check-in Simulation with Capacity LimitOA · Seen May 2026
public String solution(int[] numbers, int pivot) {
// write your code here
}numbers[1, 3, 0, -1, 1, 4, 3]
pivot2
expected"smaller"
checking account