Suppose we have a list of numbers called nums, we have to find the length of the longest increasing subsequence and we are assuming the subsequence can wrap around to the beginning of the list.
So, if the input is like nums = [6, 5, 8, 2, 3, 4], then the output will be 5, as the longest increasing subsequence is [2, 3, 4, 6, 8].
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
import bisect class Solution: def solve(self, nums): a = nums + nums ans = 0 for i in range(len(nums)): dp =  for j in range(i, len(nums) + i): n = a[j] k = bisect.bisect_left(dp, n) if k == len(dp): dp.append(n) else: dp[k] = n ans = max(ans, len(dp)) return ans ob = Solution() nums = [4, 5, 8, 2, 3, 4] print(ob.solve(nums))
[4, 5, 8, 2, 3, 4]