• + 1 comment

    The video method is O(n^2). It can be done in O(nlog(n)). First, don't store the subsquences found but add a link to the previous subsequence in the step "previous subsequence + element". Second, you don't have to go trough all previous subsequences, you can keep only those with smallest last element (for each length) and use a bisection lookup (O(log(n)) instead O(n) search). See http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms