Wiggle the towerWiggle the tower
Your input is the height map of a tower. The tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example [1,4,5,3,2]
is a valid input. Here is a visualization:
#
##
###
####
#####
14532
Your task is to wiggle the tower. Wiggling works as from top to bottom. We shift a layer to the left, or if this is not possible, shift the layer to the right and repeat for the next layer.
Here is how this input would be wiggled.
#
##
###
####
#####
14532
#
##
###
####
#####
15432
#
##
###
####
#####
23451
#
##
###
####
#####
23541
#
##
###
####
#####
24531
#
##
###
####
#####
25431
#
##
###
####
#####
34521
So if your program got [1,4,5,3,2] it should return [1,5,4,3,2].