FastPrepCount Spikes πŸ“
Problems/Count Spikes πŸ“

Count Spikes πŸ“

Amazon logoAmazon● MediumOA
QuestionFunctionExamplesConstraints

Problem statement

A k-Spike is an element that satisfies both the following conditions:

There are at least k elements from indices (0, i-1) that are less than prices[i].

There are at least k elements from indices (i+1, n-1) that are less than prices[i].

Count the number of k-Spikes in the given array.

Function

countSpikes(prices: int[], k: int) β†’ int

Examples

Example 1

prices = [1, 2, 8, 5, 3, 4]k = 2return = 2
Example 1 illustration

8 at index 2 has (1, 2) to the left and (5, 3, 4) to the right that are less than 8. 5 at index 3 has (1, 2) to the left and (3, 4) to the right that are less than 5.

Constraints

  • N/A (If you know about it, feel free to contact us :P tysm!)

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW Β· Seen Nov 2026
  • First Non-Repeating CharacterOA Β· ONSITE INTERVIEW Β· Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int countSpikes(int[] prices, int k) {
      // write your code here
    }

}
Checking account…