Ctrl K

Taller Than Distant Neighbors

Easy
You are given an array values and an integer gap. Call values[i] a standout if it is strictly greater than values[i - gap] and strictly greater than values[i + gap], comparing only against those positions that actually exist in the array. If neither position exists, the element is a standout as well. Return the sum of all standout elements.
Example 1
values=[4, 9, 2, 7, 3], gap=2 → 16

Index 0 (4) is compared only with index 2 (2) and wins. Index 1 (9) beats index 3 (7). Index 2 (2) loses to 4. Index 3 (7) loses to 9. Index 4 (3) beats 2. Total 4 + 9 + 3 = 16.

Example 2
values=[5, 5], gap=1 → 0

A tie does not count: neither 5 is strictly greater than the other, so the sum is 0.

Constraints
  • 2 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 1000
  • 1 ≤ gap ≤ ⌊len(values) / 2⌋
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
values=[4, 9, 2, 7, 3], gap=2
Expected
16

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.