public static ArrayList<Integer> longestConsecutiveIncreasingSequence(int[] arr) {
/* Your class should be named Solution
* Don't write main().
* Don't read input, it is passed as function argument.
* Return output and don't print it.
* Taking input and printing output is handled automatically.
*/
HashMap<Integer,Boolean>hm=new HashMap<>();
for(int val :arr){
hm.put(val,true);}
for(int val:arr)
{
if( hm.containsKey(val-1))
hm.put(val,false);
}
int msp=0;
int ml=0;
for (int val:arr) {
if(hm.get(val)==true){
int tsp=val;
int tl=1;
while(hm.containsKey(tsp tl)){
tl ;}
if(tl>ml){
ml=tl;;
msp=tsp; }
}
}
return (msp);
return(msp ml-1);
}
CodePudding user response:
//use this syntax to add value in arraylist and then return list.
ArrayList<Integer> list=new ArrayList<Integer>(); list.add(msp); list.add(msp ml-1); return list
CodePudding user response:
You need to return ArrayList. So, add both the values in Arraylist and then return arraylist.
ArrayList<Integer> al = new ArrayList<>();
al.add(msp);
al.add(msp ml -1);
return al;