BackmediumArrays Oracle

Astronaut's Oxygen Level Detector Solution

Problem Statement

Given a list of oxygen levels recorded by astronauts in a space station over time, find the index of the highest oxygen level reading that is greater than or equal to its neighboring readings. If no such index exists, return -1.

Example 1
Input
[1, 2, 3, 4, 5, 4, 3, 2, 1]
Output
-1

Explanation: Step-by-step: with input [1, 2, 3, 4, 5, 4, 3, 2, 1], we iterate through the array and find that the highest oxygen level reading is 5, which is not greater than or equal to its neighboring readings. Therefore, the output is -1.

Example 2
Input
[5, 5, 5, 5, 5]
Output
0

Explanation: Step-by-step: with input [5, 5, 5, 5, 5], we iterate through the array and find that all oxygen level readings are equal. Therefore, the output is 0.

Constraints

  • 1 <= oxygen_levels.length <= 1000
  • 0 <= oxygen_levels[i] <= 10000
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free