← Back to challenges

Recursion: Extreme Indices and Values

PythonHardrecursionarrays

Instructions

Write a function that extracts the upper and lower bounds of the elements in the list, value-wise, including its corresponding index, list-wise. Although these tasks are achievable with the use of some built-in Array functions, the purpose and intent of this challenge is for your to solve it recursively.

Output Structure:

[{index: lower_bound}, {index: upper_bound}]

Examples

extremes([107, 19, -18, -79, 36, 23, 97]) ➞ [{3: -79}, {0: 107}]

extremes([31, 7, 2, 13, 7, 9, 10, 13]) ➞ [{2: 2}, {0: 31}]

extremes([4, 4, 4, 4, 4, 4]) ➞ "No bounds!"

Notes

  • Return "No bounds!" if the lower bound happens to be equal to its supposed upper bound (because logically and numerically, lower and upper bound values cannot be equal, thus, their respective names (see above example).
  • The use of index(), max() and min() are restricted.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.