CT138

Arrange Stones by Closeness to Zero

EasyL2 · Byte BanditAcceptance: 0.0%XP: 10

A sculptor lays numbered stones from smallest magnitude to largest, breaking ties numerically. Task: Sort by increasing absolute value; equal magnitudes are ordered by increasing numeric value. Input format: Read n followed by n integers. Output format: Print sorted values on one line separated by single spaces. Constraints: 1 <= n <= 100000; -10^9 <= values <= 10^9

Example 1:

Input: 5 -7 2 -3 3 1
Output: 1 2 -3 3 -7

Example 2:

Input: 4 0 -1 1 -2
Output: 0 -1 1 -2

Example 3:

Input: 1 -5
Output: -5

Constraints:

1 <= n <= 100000; -10^9 <= values <= 10^9

Tags:

sorting absolute-value
Loading...
Test Cases:No test cases
No test cases available.