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!
- For
row = [-1, 150, 190, 170, -1, -1, 160, 180]
, the output should besortByHeight(row) = [-1, 150, 160, 170, -1, -1, 180, 190]
.
-
[execution time limit] 5 seconds (ts)
-
[input] array.integer
row
- If
row[i] = -1
, then the$i^{th}$ position is occupied by a tree. - Otherwise
row[i]
is the height of a person standing in the$i^{th}$ position. - Guaranteed constraints:
$1 \le row.length \le 1000$ $-1 \le row[i] \le 1000$
- If
-
[output] array.integer
- Sorted array
row
with all the trees untouched.
- Sorted array