Мне нужно сформировать новый список размера n с указанными ниже функциями. p>
Здесь i, j представляет позицию индекса выходного списка, такую что i < j < n
Код: Выделить всё
Items from 0 to i should be in increasing order strictly
Items from i to j should be in decreasing order strictly
Items from j to n should be in increasing order strictly
Пример:
Код: Выделить всё
input [2, 1, 3, 3, 1, 2, 1, 2, 3]
valid output sequence with max selected items is [1,2,3,2,1,2,3]
size of this output sequence is 7, so return the value 7
Код: Выделить всё
increasing from position 0 to 2 => [1,2,3]
decreasing from position 2 to 4 => [3,2,1]
again increasing from position 4 to last index => [1,2,3]
Код: Выделить всё
input [5, 5, 2, 1, 3, 4, 5]
valid output sequence with max selected items is [1, 3, 5, 4, 2, 5]
size of this output sequence is 6, so return the value 6
Код: Выделить всё
increasing from position 0 to 2 => [1,3,5]
decreasing from position 2 to 4 => [5,4,2]
again increasing from position 4 to last index => [2,5]
ввод [2, 1, 3, 3, 1, 2, 1, 2, 3]
Вывод : 7
Код: Выделить всё
**Example:**
input = [1,100]
for this input we can get the updated sequence as [100, 1]
a) increasing part = [100], here i = 0
b) decreasing part = [100, 1], here i=0, j=1
c) increasing part = [1], here j to end, j = 1
ограничения:
2
Подробнее здесь: https://stackoverflow.com/questions/791 ... of-numbers
Мобильная версия