FastPrepCompare Counts Around a Pivot

Compare Counts Around a Pivot

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Given integers numbers and pivot, count values strictly greater than the pivot and strictly less than it. Values equal to the pivot belong to neither count.

Return "greater", "smaller", or "tie" according to which count is larger.

Function

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

Examples

Example 1

numbers = [1,5,7,5,2]pivot = 5return = "smaller"

Two values are smaller, one is greater, and the two fives are ignored.

Example 2

numbers = [1,9]pivot = 5return = "tie"

One value lies on each side of the pivot.

Constraints

  • 0 <= numbers.length <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String compareAroundPivot(int[] numbers, int pivot) {
    // Write your code here.
}
numbers[1,5,7,5,2]
pivot5
expected"smaller"
Checking account…