Tap here to switch tabs
Problem
Submissions

Problem: The k Strongest Values in an Array

med
30 min
Try to solve the The k Strongest Values in an Array problem.

Statement

Given an integer array arr and an integer k.

A value arr[i] is considered stronger than a value arr[j] if:

  • ∣|arr[i] - m∣>∣| > |arr[j] - m∣|, or

  • ∣|arr[i] - m∣=∣| = |arr[j] - m∣| and arr[i] >> arr[j]

where m is the median of arr.

The median of an array of length n is the value at index (n−1)/2(n - 1) / 2 after sorting the array in non decreasing order, using 00 based indexing.

Return an array of the k strongest values in arr. The result can be returned in any order.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • −105≤-10^5 \leq arr[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤\leq arr.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The k Strongest Values in an Array

med
30 min
Try to solve the The k Strongest Values in an Array problem.

Statement

Given an integer array arr and an integer k.

A value arr[i] is considered stronger than a value arr[j] if:

  • ∣|arr[i] - m∣>∣| > |arr[j] - m∣|, or

  • ∣|arr[i] - m∣=∣| = |arr[j] - m∣| and arr[i] >> arr[j]

where m is the median of arr.

The median of an array of length n is the value at index (n−1)/2(n - 1) / 2 after sorting the array in non decreasing order, using 00 based indexing.

Return an array of the k strongest values in arr. The result can be returned in any order.

Constraints:

  • 1≤1 \leq arr.length ≤105\leq 10^5

  • −105≤-10^5 \leq arr[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤\leq arr.length