Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Jan 4, 2024
1 parent 660c59d commit d924878
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions coding_interviews/algoexpert/longest-peak/longest-peak.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* Write a function that takes in an array of integers and returns
* the length of the longest peak in the array.
* A peak is defined as adjacent integers in the array that are
* strictly increasing until they reach a tip (the highest value in
* the peak), at which point they become strictly decreasing.
* At least three integers are required to form a peak.
* For example, the integers 1, 4, 10, 2 form a peak, but the
* integers 4, 0, 10 don't and neither do the integers 1, 2, 2, 0.
* Similarly, the integers 1, 2, 3 don't form a peak because there
* aren't any strictly decreasing integers after the 3.
*
* Input: array = [1, 2, 3, 3, 4, 0, 10, 6, 5, -1, -3, 2, 3]
* Output: 6 // 0, 10, 6, 5, -1, -3
*/

// Runtime: O(N), N = array length
// Space: O(1)

Expand Down

0 comments on commit d924878

Please sign in to comment.