1

How can I find the length of Longest Increasing Sub-sequence if the numbers are arranged in circular fashion. For example:

LIS of 3, 2, 1 is 3 [1, 2, 3].

P.S I know how to solve Linear LIS in O(nlogn).

Problem Source: https://www.codechef.com/problems/D2/

Update: The LIS has to be calculated by going through the circle only once. Example 2: LIS of 1, 4, 3 is 2 and that could be either of 1, 3 or 1, 4 or 3, 4.
Thanks

bewithaman
  • 768
  • 8
  • 16

1 Answers1

0

The example in question is wrong. circular rotation of [1,2,3] would be [2,3,1] or [3,1,2].

In which case, we can solve it similar way as longest increasing subsequence. As:

  1. Sort the list in ascending order.

  2. Find min element in the original list.

  3. Start iteration from min_index in original list and compare it with sorted list, and create intermediate array L[i][j] with same logic as longest common subsequence. i will vary from min_index to (i+n-1)%n
  4. Finally return L[max_index][n]