diff options
| author | MatthiasMuth <99873492+MatthiasMuth@users.noreply.github.com> | 2023-05-21 21:59:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-21 21:59:46 +0200 |
| commit | dba8fa4ad8ac05cd7f92b1b8df63857d1d4b59c4 (patch) | |
| tree | deefa7edb1683505d41b95954b0dfc5b51a1a6e1 /challenge-071/lubos-kolouch/python/ch-1.py | |
| parent | f6448daebe7cffd67e484af066ebd21ad8e614b4 (diff) | |
| parent | 87c0bedd3ccc6c2459b62fc91429676507504d15 (diff) | |
| download | perlweeklychallenge-club-dba8fa4ad8ac05cd7f92b1b8df63857d1d4b59c4.tar.gz perlweeklychallenge-club-dba8fa4ad8ac05cd7f92b1b8df63857d1d4b59c4.tar.bz2 perlweeklychallenge-club-dba8fa4ad8ac05cd7f92b1b8df63857d1d4b59c4.zip | |
Merge branch 'manwar:master' into muthm-217
Diffstat (limited to 'challenge-071/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-071/lubos-kolouch/python/ch-1.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-071/lubos-kolouch/python/ch-1.py b/challenge-071/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..7a92d52f8b --- /dev/null +++ b/challenge-071/lubos-kolouch/python/ch-1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from typing import List + + +def find_peaks(arr: List[int]) -> List[int]: + n = len(arr) + # Initialize peaks list with the first element if it's bigger than the second + peaks = [arr[0]] if arr[0] > arr[1] else [] + + # Iterate over the array checking for peaks + for i in range(1, n-1): + if arr[i] > arr[i-1] and arr[i] > arr[i+1]: + peaks.append(arr[i]) + + # Add the last element if it's bigger than the penultimate + if arr[-1] > arr[-2]: + peaks.append(arr[-1]) + + return peaks + + +# Tests +print(find_peaks([18, 45, 38, 25, 10, 7, 21, 6, 28, 48])) # [48, 45, 21] +print(find_peaks([47, 11, 32, 8, 1, 9, 39, 14, 36, 23])) # [47, 32, 39, 36] |
