We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defbinarySearch(arr,low,high,key):whilelow<=high:mid=(low+high)// 2ifarr[mid]<key:low=mid+1else:high=mid-1returnlowdeflongestIncreasingSubsequence(arr):n=len(arr)lis=[0]*nlength=0foriinrange(n):pos=binarySearch(lis,0,length-1,arr[i])lis[pos]=arr[i]ifpos==length:length+=1returnlength# Reading inputn=int(input())arr=[int(input())for_inrange(n)]# Finding and printing the length of the LISresult=longestIncreasingSubsequence(arr)print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Longest Increasing Subsequence
You are viewing a single comment's thread. Return to all comments →