Link Search Menu Expand Document

Last Positive

Print the last positive number in a given array of integers.

E.g. for [1, 3, 5, -1, 6] the output should be 6, whereas for [1, 3, 5, -1, -6] the output should be 5

Bonus point: Print the 0-based index of the last positive number instead of the the number itself. I.e. in the examples about for the first one the output should be 4, while for the second one it should be 2