nice explanation..
P
prakash_karamshi
@prakash_karamshi
0
Reputation
9
Posts
77
Profile views
0
Followers
8
Following
Posts made by prakash_karamshi

RE: Two Solutions (with explanation): O(nlog(n)) and O(n) time , O(1) space, without changing the input array
@caikehe high is 5 since high = <Array.length>  1

Didn't understood the question?
If we need to check weather subsequence can be split in to two or more subsequence with at least 3 consecutive integers, then how [1,2,3]? can be split in two subsequence.

RE: Java Code by using binary search O(log(n))
@inswingingyorker I have the same line in my code it is for the case when the single element is the last element..see this test case
[3,3,7,7,8,8,10,10,11]
Hope this helps.. Correct me if i am wrong 
RE: Java Binary Search, short (7l), O(log(n)) w/ explanations
Great solution..Easy to understand..

Java solution using DP O(n) space O(m) m is max ring size
int max = 0; int mem[] = new int[nums.length]; Arrays.fill(mem,1); for(int i=0;i<nums.length;i++){ max = Math.max(helper(nums,i,mem),max); } return max; } public int helper(int[] nums, int k,int mem[]){ if(mem[k] != 1){//get count if already computed return mem[k]; } int[] arr = new int[nums.length]; arr[nums[k]] = 1; int i = nums[k],count = 2; while(!map.containsKey(nums[i])){ map.put(nums[i],count); i = nums[i]; count++; } int n = map.size(); for(Integer key:map.keySet()){ // store the ring for all in between index mem[key] = n  map.get(key); } mem[k] = n; return mem[k]; }```