The input list starts in strictly ascending order until it reaches a maximum and the it follows a strictly descending order until end of the list , [-10, -8, -5...10]
[1, 4, 6, 5, 3] -> [1, 3, 4 ,5 , 6]
_
_ _
_
A list [-10, -5, 1 ,3 ,6, 10, 9, 2, -8]. Write a function that takes this list and returns a list only in ascending order
sorted(list)
lista1 = list[0:max_idx] // [ 3, 6, 10, 11,12,13] n
lista2 = reversed(list[max_idx,:]) // n -> n
lista_final = [-10, -8, -5, 1, 2, 3, 6, 9, 10, 11, 12, 13]
while(true) {
if(!lista.hasNext() || !lista2.hasNext()) {
if(lista1.hasNext()) {
lista_final.addAll(lista1)
}
if(lista2.hasNext()) {
lista_final.addAll(lista2)
}
break;
}
if(lista1.peek() < lista2.peek()) {
lista_final.add(lista1.pop())
} else {
lista_final.add(lista2.pop())
}
}