Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees. People can be very tall!
Example
For a = [-1, 150, 190, 170, -1, -1, 160, 180]
, the output should be
solution(a) = [-1, 150, 160, 170, -1, -1, 180, 190]
.
Input/Output
-
[execution time limit] 3 seconds (java)
-
[memory limit] 1 GB
-
[input] array.integer a
If
a[i] = -1
, then theith
position is occupied by a tree. Otherwisea[i]
is the height of a person standing in theith
position.Guaranteed constraints:
1 ≤ a.length ≤ 1000
,
-1 ≤ a[i] ≤ 1000
. -
[output] array.integer
Sorted array
a
with all the trees untouched.
[Java] Syntax Tips
-
CodeSignalSolutions/Sort_By_Height/Sort_by_height.js
Lines 1 to 23 in bfe6e99
-
CodeSignalSolutions/Sort_By_Height/Sort_by_height.java
Lines 16 to 38 in bfe6e99