Watch the LIS dynamic programming array build up on 3 10 2 1 20 4 6 15, then trace the answer back. Type your own array, and see the O(n log n) method too.
About this algorithm
The longest increasing subsequence (LIS) of a list is the longest run of values you can pick, keeping their original order, where each value is bigger than the one before and the picked values do not have to sit next to each other. Dynamic programming finds it by working out, for every position, the longest such run that ends exactly there.
Use LIS when you need the longest chain that keeps both an order and a growing value: the most boxes you can stack, the most envelopes you can nest (LeetCode 354), the fewest items to delete to leave a list sorted (n minus the LIS). It is LeetCode 300. The O(n²) table here is easy to follow and lets you read off the actual sequence; for long inputs use the O(n log n) method in the note below. Longest common subsequence compares two lists rather than one, and Kadane's algorithm finds a contiguous block with the largest sum, not an ordered chain.
Set dp[i] = 1 for every index, since a single value is an increasing run by itself. Set prev[i] = -1 to mean nothing comes before it yet.
For each i, check every j before it. If arr[j] is smaller than arr[i], then arr[i] can extend the best run ending at j, giving a run of dp[j] + 1.
If dp[j] + 1 beats dp[i], set dp[i] to it and remember prev[i] = j. Also track the largest dp value seen and where it ends.
Start at the index with the largest dp and follow prev links until you reach -1. Reverse the values you collected.
The page opens on 3 10 2 1 20 4 6 15. 10 extends 3, so its run is 2. 2 and 1 have nothing smaller before them and stay at 1. 20 can follow 3 or 10; following 10 gives 3. 4 can only follow 3, 2 or 1, each a run of 1, so it gets 2. 6 can follow 4, giving 3. 15 checks everything before it: 10 would give 3, but 6 gives 4. The finished table is 1 2 1 1 3 2 3 4, so the answer is 4, ending at 15. The prev links lead 15 to 6 to 4 to 3, so the page shows 3, 4, 6, 15. Runs 2, 4, 6, 15 and 1, 4, 6, 15 are just as long; the page keeps the first predecessor it found for each value. The other presets, 10 9 2 5 3 7 101 18 and 0 1 0 3 2 3, both give 4.
Keep a list tails, where tails[k] is the smallest value that can end an increasing run of length k + 1. For each value, binary search tails for the first entry not smaller than it and replace that entry, or append the value if none exists. On this input tails goes 3, then 3 10, 2 10, 1 10, 1 10 20, 1 4 20, 1 4 6, and finally 1 4 6 15: length 4. tails is not itself an answer, it only gives the length unless you also store links.
Time: each of the n positions looks back at every earlier one, which is about n²/2 comparisons. Space: two arrays of length n, dp for the run lengths and prev for the links.