We have an array of integer numbers. We want to know for each element whether that element is contained at least in one LIS of many LISs of our array or not. We want to know this for all elements in the array in less than O(n2).
For example array [2, 4, 3, 2, 5] has two LISs. All elements in the array belong to at least one of these LISs, exept the 4th element which does not belong to any LIS.
I know an easy solution which uses dfs, but its runtime is O(n2).
Run an algorithm such as https://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms which computes, at each point, the length of the longest increasing subsequence ending at that point.
Run the same algorithm using the data in reversed order, to compute, for each point, the length of the longest increasing subsequence starting at that point.
For each point add the two computed lengths. The point is on a longest increasing subsequence if this sum is equal to the largest sum found.
The alogorithm quoted takes time O(n log n) for each pass and the sum is only O(log n) so the total is O(n log n)