MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / findLongestConseqSubseq

Method findLongestConseqSubseq

LongestCommonSubsequence.java:32–43  ·  view source on GitHub ↗
(int arr[], int N)

Source from the content-addressed store, hash-verified

30
31// Sorting solution
32static int findLongestConseqSubseq(int arr[], int N)
33 {
34 int count=1,counter=1;
35 Arrays.sort(arr);
36 for(int i=1;i<N;i++)
37 {
38 if(arr[i]-arr[i-1]==1) count++;
39 else if(arr[i]-arr[i-1]!=0) count=1;
40 counter = Math.max(counter,count);
41 }
42 return counter;
43}

Callers

nothing calls this directly

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected