We are given an array of integers of size n, which is not necessarily sorted, and we want to create a sub array. We are allowed to do one of 3 tasks below in each level:
1. skip the number in original array and go to the next
2. insert the number in the start of the sub array
3. insert the number in the end of the sub array.
And at last we want the sub array to be the longest one that can be created with the conditions above and sorted.
For example we have A={10,3,13}
now we can insert 10 in the beginning, then 3 at the beginning and finally insert 13 in the end.
so the size of sub array is 3.
I know that I must solve this using dynamic programming but I do not know how to do it exactly.
10,2,7,4,3,13
gives3,4,7,10,13
as the only maximum valid subarrary $\endgroup$