Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

incompatible types how can i return the two values in java

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);
        
    }

>Solution :

//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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading