BackmediumArrays Infosys

Galaxy Anomaly Detector Solution

Problem Statement

Given a list of distinct asteroid sizes in a galaxy, find all asteroid sizes that are larger than their neighboring asteroids.

Example 1
Input
[50, 20, 30, 40, 50]
Output
[50]

Explanation: Step-by-step: Given the input [50, 20, 30, 40, 50], we first identify the asteroid sizes that are larger than their neighboring asteroids. In this case, 50 is larger than its neighbors 20, 30, and 40. Therefore, the output is [50].

Example 2
Input
[7, 5, 9, 8, 7]
Output
[7, 9, 8]

Explanation: Step-by-step: Given the input [7, 5, 9, 8, 7], we first identify the asteroid sizes that are larger than their neighboring asteroids. In this case, 7 is larger than its neighbors 5 and 7, 9 is larger than its neighbors 5 and 8, and 8 is larger than its neighbors 5 and 7. Therefore, the output is [7, 9, 8].

Constraints

  • The list of asteroid sizes will have at least 3 elements.
  • All asteroid sizes will be distinct integers between 1 and 100.
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