Perl Weekly Challenge 71: Peak Elements and Trim Linked List
These are some answers to the Week 71 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Task 1: Peak Elements
You are given positive integer $N (>1).
Write a script to create an array of size $N with random unique elements between 1 and 50.
In the end it should print peak elements in the array, if found.
An array element is called peak if it is bigger than it’s neighbour.
Example 1:
Array: [ 18, 45, 38, 25, 10, 7, 21, 6, 28, 48 ]
Peak: [ 48, 45, 21 ]
Example 2:
Array: [ 47, 11, 32, 8, 1, 9, 39, 14, 36, 23 ]
Peak: [ 47, 32, 39, 36 ]
The specification somewhat lacks precision, but the examples are clear enough to clarify.