← Back to challenges

Recursion: Parity of the Smallest Integer

PythonHardrecursionarrays

Instructions

Write a function that returns the smallest integer in a list with its corresponding index and its parity. Although these tasks can be equivocally achievable with the use of some built-in and list functions, the purpose and intent of this challenge is for you to solve it recursively.

Output Structure:

{"@index " + index_of_smallest: smallest_integer, "parity": "odd|even"}

Examples

bitwise_one_zero([107, 19, -18, -79, 36, 23, 97]) ➞ {"@index 3": -79, "parity": "odd"}

bitwise_one_zero([31, 7, 2, 13, 7, 9, 10, 13]) ➞ {"@index 2": 2, "parity": "even"}

bitwise_one_zero([3, 3, 3, 3, 3, 3]) ➞ {"@index 0": 3, "parity": "odd"}

Notes

  • The use of index() and min() are restricted.
  • You can read more about recursion if you aren't familiar with it or haven't fully understood the concept before taking up this challenge.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.