Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created June 17, 2020 23:32
Show Gist options
  • Save ZechCodes/cd68cfccdc865377e1c90dc9e7951d0b to your computer and use it in GitHub Desktop.
Save ZechCodes/cd68cfccdc865377e1c90dc9e7951d0b to your computer and use it in GitHub Desktop.
Challenge #31 - Mini Peaks

Challenge 31 - Mini Peaks

Write a function that returns all the elements in an array that are strictly greater than their adjacent left and right neighbors.

Examples

mini_peaks([4, 5, 2, 1, 4, 9, 7, 2]) ➞ [5, 9]

mini_peaks([1, 2, 1, 1, 3, 2, 5, 4, 4]) ➞ [2, 3, 5]

mini_peaks([1, 2, 3, 4, 5, 6]) ➞ []

Notes

  • Do not count boundary numbers, since they only have one left/right neighbor.
  • If no such numbers exist, return an empty array.
import unittest
from typing import List
def mini_peaks(numbers: List[int]) -> List[int]:
return [] # Put your code here!!!
class TestMiniPeaks(unittest.TestCase):
def test_1(self):
self.assertEqual(mini_peaks([4, 5, 2, 1, 4, 9, 7, 2]), [5, 9])
def test_2(self):
self.assertEqual(mini_peaks([1, 2, 1, 1, 3, 2, 5, 4, 4]), [2, 3, 5])
def test_3(self):
self.assertEqual(mini_peaks([1, 2, 3, 4, 5, 6]), [])
def test_4(self):
self.assertEqual(mini_peaks([6, 4, 3]), [])
def test_5(self):
self.assertEqual(mini_peaks([1, 1, 1, 1, 2, 1, 1, 1]), [2])
def test_6(self):
self.assertEqual(mini_peaks([1, 9, 1, 8, 2, 7, 6]), [9, 8, 7])
def test_7(self):
self.assertEqual(mini_peaks([7, 8, 7, 8, 7, 8, 5, 1, 2, 0]), [8, 8, 8, 2])
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment