From 2062d8c6418f72d5dc83156c0bfe99d2837aeb16 Mon Sep 17 00:00:00 2001 From: NOOBIE666 <129605338+NOOBE666@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:21:42 +0530 Subject: [PATCH] Update Hashmaps: Longest consecutive Sequence Less lines of code,passed all the test cases. I think better than previous solution in time complexsity. --- Hashmaps:Longest consecutive Sequence | 94 ++++++++++----------------- 1 file changed, 33 insertions(+), 61 deletions(-) diff --git a/Hashmaps:Longest consecutive Sequence b/Hashmaps:Longest consecutive Sequence index ab7b6b5..77cf03b 100644 --- a/Hashmaps:Longest consecutive Sequence +++ b/Hashmaps:Longest consecutive Sequence @@ -1,65 +1,37 @@ - - - +import java.util.Map; import java.util.HashMap; import java.util.ArrayList; +import java.util.Arrays; + public class Solution { public static ArrayList longestConsecutiveIncreasingSequence(int[] arr) { - HashMap map = new HashMap<>(); - ArrayList output = new ArrayList<>(); - - 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 map=new HashMap<>(); + ArrayList arrayList=new ArrayList<>(); + ArrayList arrayListcopy=new ArrayList<>(); + for(int i=0;iarrayList.size()){ + arrayList=arrayListcopy; + } + arrayListcopy=new ArrayList<>(); + } + ArrayList output=new ArrayList<>(); + output.add(arrayList.get(0)); + output.add(arrayList.get(arrayList.size()-1)); + + return output; + } +}