BackmediumArrays Cred

Galactic Transmission Solution

Problem Statement

Given a sequence of numeric codes representing asteroid positions and a specified number of cosmic events, determine the lexicographically smallest sequence after applying these events. The 'pulsar' event sorts the array in ascending order, and the 'blackhole' event multiplies each element by -1.

Example 1
Input
[-12, -8, -5, -3]
Output
[-12, -8, -5, -3]

Explanation: Step 1: Apply the 'pulsar' event. Since the input array is already sorted in ascending order, the 'pulsar' event does not change the array. The output remains the same: [-12, -8, -5, -3]. Step 2: Apply the 'blackhole' event. Each element in the array is multiplied by -1. The output becomes: [12, 8, 5, 3].

Example 2
Input
[14, 9, 7, 2]
Output
[14, 9, 7, 2]

Explanation: Step 1: Apply the 'blackhole' event. Each element in the array is multiplied by -1. The output becomes: [-14, -9, -7, -2]. Step 2: Apply the 'pulsar' event. The array is sorted in ascending order. The output remains the same: [-14, -9, -7, -2].

Constraints

  • Array length will be between 3 and 1000 elements.
  • The number of operations will range from 1 to 10^5.
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