From f1dc33f2e5b1ac5d2374c9da44f3ee724b2f4dc0 Mon Sep 17 00:00:00 2001 From: darksoul-7 <110017411+darksoul-7@users.noreply.github.com> Date: Tue, 11 Oct 2022 10:31:50 +0530 Subject: [PATCH] Check the new corrected code The previous code have an error in it. so please check the new code --- Hashmaps:Longest consecutive Sequence | 121 ++++++++++++++++---------- 1 file changed, 74 insertions(+), 47 deletions(-) diff --git a/Hashmaps:Longest consecutive Sequence b/Hashmaps:Longest consecutive Sequence index ab7b6b5..a3aa4f0 100644 --- a/Hashmaps:Longest consecutive Sequence +++ b/Hashmaps:Longest consecutive Sequence @@ -5,61 +5,88 @@ import java.util.HashMap; import java.util.ArrayList; public class Solution { public static ArrayList longestConsecutiveIncreasingSequence(int[] arr) { - HashMap map = new HashMap<>(); - ArrayList output = new ArrayList<>(); - - for(int i=0;i longestConsecutiveIncreasingSequence(int[] arr) { + ArrayList output = new ArrayList<>(); + HashMap map = new HashMap<>(); + HashMap lenMap = new HashMap<>(); + for (int i=0 ; i < arr.length ; i++) + { map.put(arr[i],true); } + int maxStart=-1,maxLen=0; + boolean startCheck=true; - int maxlength = 0; - int start = 0; - - for(int i=0;i maxlength){ - maxlength = length; - start = starttemp; - }else if(length == maxlength){ - maxlength = length; - //start = 10 starttemp = 4 - for(int j=0;j=maxLen) + { + maxLen=currLen; + maxStart=currStart; + lenMap.put(maxStart,maxLen); + } } - // else{ - // continue; - // } + } - for(int i = start;i=maxLen) + { + maxStart=arr[i]; + maxLen=lenMap.get(arr[i]); + break; + } + } + output.add(maxStart); + output.add(maxStart+maxLen-1); + return output; + } + }