Recursion: Index Parity of Largest Even

Published by Deep Xavier in

Finding an even integer in an list is kind of trivial and superficial to most programming enthusiasts. This challenge will take it to the next level.

Write a function that returns the largest even integer in a list with its corresponding index and the parity of that index, but determining the parity of that index is limited to not using the modulo operator %. Therefore, devise a way to resolve it.

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

{"@odd|even index " + index_of_largest: largest_integer}

Examples

bitwise_index([107, 19, 36, -18, -78, 24, 97]) ➞ {"@even index 2": 36}

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

bitwise_index([4, 4, 4, 4, 4, 4]) ➞ {"@even index 0": 4}

bitwise_index([-31, -7, -13, -7, -9, -13]) ➞ "No even integer found!"

Notes

  • The use of the modulo operator %, index() and max() functions are restricted.
  • You can read more about recursion (see Resources tab) if you aren't familiar with it yet or haven't fully understood the concept before taking up this challenge.
Watch a quick demo on how Edabit works.