-2

You must solve it with O(n^2). (This is could be equal with the length of LIS, such as "13245")

1 Answers1

0

This problem can be reduces to:

Check if there exist two or more different LIS's (with the same maximum length of course).
If the answer is yes - the "second"-LIS is obviously the same length as the LIS.
If the answer is no - the second-LIS length is the length of the longest one minus 1.

In order to find the number of LIS's you can simply modify the O(n^2) algorithm described here to keep track of not only the maximum length but also the number of those maximums.

Community
  • 1
  • 1
A. Sarid
  • 3,916
  • 2
  • 31
  • 56