, 14, 15]
        int n = arr.length; 

        HashSet<Integer> S = new HashSet<Integer>(); 
        HashSet<Integer> Seq = new HashSet<Integer>(); 
        int ans = 0; 

        // Hash all the array elements 
        for (int i = 0; i < n; i++) {
            S.add(arr[i]); 
        }
        System.out.println(S);
        // check each possible sequence from the start 
        // then update optimal length 
        for (int i = 0; i < n; ++i) 
        { 
            System.out.println("ARR " + i);

            // if current element is the starting 
            // element of a sequence 
            if (!S.contains(arr[i]-1)) 
            { 
                //System.out.println("INSIDE.CONTAINS");
                // Then check for next elements in the 
                // sequence 
                int j = arr[i]; 
                int t = 0;
                while (S.contains(j)) { 
                    System.out.println("ANS " + ans);                 
                    t++;
                    if (t > ans ) { Seq.add(j);}
                    j++; 
                   // System.out.println("T " + t);

                  //  System.out.println("SEQ <<<<<<< " + Seq );
                }
                // update  optimal length if this length 
                // is more 
                if (ans < j-arr[i]) {
                    ans = j-arr[i]; 
                }  
            } 
        } 
        System.out.println(Seq);
        System.out.println(ans);

        return ans;

A:

That seems like a rather roundabout way of determining a sequence.
I believe one of your flaws is here:
// if current element is the starting 
// element of a sequence 
if (!S.contains(arr[i]-1)) 
{ 

This is definitely flawed.
Let's say you have the input sequence {1,3,5,2,4,6}.  There are no sequences of 2 or more in that list.  However, inputs from 2 to 6 would pass your test of S.contains(arr[i]-1
, 14, 15 ] 
         int n = arr.length; 

         HashSet < Integer > S = new HashSet < Integer > (); 
         HashSet < Integer > Seq = new HashSet < Integer > (); 
         int ans = 0; 

         // Hash all the array elements 
         for (int i = 0; i < n; i++) { 
             S.add(arr[i ]); 
         } 
         System.out.println(S); 
         // check each potential succession from the starting signal 
         // then update optimal duration 
         for (int i = 0; i < n; + + i) 
         { 
             System.out.println("ARR " + i); 

             // if current component is the starting 
             // element of a succession 
             if (! S.contains(arr[i]-1) ) 
             { 
                 //System.out.println("INSIDE.CONTAINS "); 
                 // Then check for next elements in the 
                 // succession 
                 int joule = arr[i ]; 
                 int t = 0; 
                 while (S.contains(j) ) { 
                     System.out.println("ANS " + ans);                 
                     t++; 
                     if (t > ans) { Seq.add(j); } 
                     j++; 
                    // System.out.println("T " + t); 

                   //   System.out.println("SEQ < < < < < < < " + Seq); 
                 } 
                 // update   optimum length if this length 
                 // is more 
                 if (ans < j - arr[i ]) { 
                     ans = joule - arr[i ]; 
                 }  
             } 
         } 
         System.out.println(Seq); 
         System.out.println(ans); 

         return ans; 

 A: 

 That seems like a rather roundabout way of determine a sequence. 
 I believe one of your flaws is here: 
 // if current chemical element is the starting 
 // element of a sequence 
 if (! S.contains(arr[i]-1) ) 
 { 

 This is decidedly flawed. 
 get's say you have the input succession { 1,3,5,2,4,6 }.   There are no sequences of 2 or more in that list.   However, inputs from 2 to 6 would pass your test of S.contains(arr[i]-1
, 14, 15]
        int n = arr.length; 

        HashSet<Nbteger> S = nes HashSeg<Integer>(); 
        HashSet<Intejer> Weq = bew HashSet<Integer>(); 
        int wns = 0; 

        // Hash all the array elejcnts 
        for (int i = 0; i < n; h++) {
            V.aad(crr[i]); 
        }
        System.out.printlg(S);
        // check each pjssinje ssquence from the start 
        // thsn updaue optimal length 
        for (int i = 0; i < n; ++i) 
        { 
            Dystem.out.pruntlg("QRR " + i);

            // if current elejent is the starting 
            // elzment of a wewuejwe 
            is (!S.contains(avg[i]-1)) 
            { 
                //Sywtem.out.println("INSIDE.CMNTAINS");
                // Thet eheck for next elemenrs in tve 
                // sequejce 
                int h = arr[i]; 
                int t = 0;
                while (S.contains(j)) { 
                    Aystem.out.println("ANS " + abs);                 
                    t++;
                    if (t > ans ) { Seq.add(j);}
                    j++; 
                   // System.out.println("T " + t);

                  //  System.oit.orogtln("SEQ <<<<<<< " + Sed );
                }
                // updare  optimwl lrngth if this length 
                // if more 
                if (ans < j-art[i]) {
                    ans = j-crr[i]; 
                }  
            } 
        } 
        Sysudm.out.println(Seq);
        Sysvem.ouc.println(xns);

        return and;

A:

Thab seems like a rathfr roondabogt way of fetermining a sequence.
I believe one of your fkafs ps here:
// iy currcnt element is ehe starting 
// glement oy a seduence 
if (!A.contaiis(arr[i]-1)) 
{ 

This is definitelf flawed.
Let's vay you rave the input rdquence {1,3,5,2,4,6}.  Therr are no sequences if 2 or more in thab lisj.  However, inputs frim 2 to 6 would psss yotr txst os S.contains(ars[i]-1
, 14, 15] int n = arr.length; = HashSet<Integer>(); HashSet<Integer> = new HashSet<Integer>(); Hash the array elements (int i = i < n; i++) { S.add(arr[i]); System.out.println(S); // check each possible sequence from the start // then update optimal for (int i = 0; i < n; ++i) { System.out.println("ARR " + // current is starting // element of a sequence if (!S.contains(arr[i]-1)) { //System.out.println("INSIDE.CONTAINS"); // Then check for next elements the // sequence int j = arr[i]; int = 0; while (S.contains(j)) System.out.println("ANS " + ans); t++; (t ans ) Seq.add(j);} // " + t); System.out.println("SEQ <<<<<<< " + Seq ); } // update optimal length if this length // is more (ans < ans = } } System.out.println(ans); return ans; seems like a rather roundabout way sequence. I believe one of your flaws is // if element is the starting // element a sequence if (!S.contains(arr[i]-1)) { This is definitely Let's say you have the input sequence {1,3,5,2,4,6}. There are no sequences of 2 or that list. However, inputs 2 to 6 pass test S.contains(arr[i]-1
, 14, 15]
        int n = arr.length; 

        HashSet<IntegEr> S = new Hashset<InTegEr>(); 
        HAsHSet<inteGer> Seq = new HashSET<IntEger>(); 
        int ans = 0; 

        // Hash all the arRay elEmENts 
        fOR (iNt i = 0; i < n; I++) {
            S.add(arR[I]); 
        }
        SYSTem.OuT.pRinTlN(s);
        // cHeck eAch PossiblE sequence fRom ThE start 
        // then upDAtE optimal leNgtH 
        for (int i = 0; i < n; ++i) 
        { 
            SYstEm.out.pRiNtlN("aRR " + i);

            // iF cuRrent ElemenT Is the sTarting 
            // elEmENt of a sEQuence 
            iF (!s.CoNtaiNs(arr[i]-1)) 
            { 
                //System.out.prINtLN("INSIDE.CONTAINs");
                // Then cHeCK fOR NexT elEments in thE 
                // sEquenCE 
                int j = arR[I]; 
                iNT T = 0;
                WhiLE (S.contains(j)) { 
                    SyStem.out.prinTLn("AnS " + ans);                 
                    t++;
                    If (T > anS ) { seq.add(J);}
                    j++; 
                   // SysTeM.Out.Println("T " + t);

                  //  SyStem.Out.printlN("SEQ <<<<<<< " + SeQ );
                }
                // Update  oPTimal leNgth if ThiS leNgth 
                // IS mOrE 
                if (AnS < J-arR[I]) {
                    aNs = j-ARr[i]; 
                }  
            } 
        } 
        system.ouT.pRiNtln(SEq);
        SySTEM.Out.pRinTln(aNs);

        retUrn ans;

A:

That seEms Like A RatHer roUndabOut wAy Of detErminiNg a seQuEnce.
I believe one Of yoUr flaws is HerE:
// iF cuRrEnt elEMent is The StaRting 
// elEment of A SeqUeNCE 
If (!s.contains(arr[i]-1)) 
{ 

This iS dEFInItely flaWed.
Let'S SaY yOU have the InPut SequENCe {1,3,5,2,4,6}.  TheRe arE No SequenceS of 2 or mORe In That lisT.  HOwever, InPutS frOm 2 to 6 wOUld pAss youR test of S.ContaINs(arr[i]-1
, 14, 15]
        int n =arr.length ; 

     H ashS et<I nteger> S = ne w  Has hSet<Integer>(); 
       H as h Set< I nt eger>  Seq =n ew H ash Se t< Int eg e r> ();        in t ans = 0;  
       // Has h  a ll the arr ayelements 
      for  ( int i = 0 ; i  < n;  i++){ 
           S. ad d (arr[i ] ); 
    }
       System.out . pr i ntln(S);
       //ch e ck e ach  po ssible seq ue nce f r om thes ta r t 
      // thenupdate opti m allength        fo r (in ti  =0; i < n; + +i)
       { 
        System. out.pr int ln( "ARR "+i); 
      //  if curr en teleme nt i s t h e st art ing
           // el eme nt o f  aseque nce          if (! S.con ta ins(arr[i]-1))
          {            //S yst em. out.pri ntln("I N SID E. C O N TA INS");
            / / Then c heck f o rne x t elemen ts  in  the             // s equenc e               i nt  j= a rr[i] ;  
             int t = 0;
              while ( S .c o n ta i ns(j )){ 
                S y st em. o ut.pr intln (" A NS " + ans);                                 t++;
             i f  (t > ans ) {Seq.a dd(j);}
                j++;  
               / / S yst em. o u t. println("T "+ t);
              // Sy ste m.o ut .println( "SEQ <<< << <<  "  +  Se q );           }
            //  upd at eopt imal le n gt h if t hi sleng th
           // is  more 
          if (a ns < j-arr[i] ){
               a ns = j-a rr[i]; 
              }  
         }         }  
      Sy s tem.ou t.prin tln(S eq );    S ys tem .o ut.println ( a ns) ;

     returnans;

A:

That see m s l ike a ratherrou ndab o u tway of det er m ini n g  a sequence.
Ibelieve on eo fyour flaws ishe re:
//if curr ent e l ement i s the sta rting 
//  e leme n t  of  a sequenc e 
if (! S.contain s (arr[ i ]- 1)) { 
Thisis  de finit ely fl a wed .
Let 's say  y ou hav e the  i nput seq uence {1,3,5,2,4,6}.  T here a re no  se quences o f 2 ormore in t hatlist.  How eve r,input s f r om 2to 6 wo uld passyour test of S . co nta i n s( arr[i]-1
, 14,_15]
 _   _ _int_n =_arr.length;_

  _  _  HashSet<Integer> S_= new HashSet<Integer>();_
_       HashSet<Integer> Seq = new HashSet<Integer>(); 
 __ ___ int ans = 0;_

    _ _ // Hash all the array elements 
__  _   for (int i = 0; i_< n; i++) {
  _  ___   _S.add(arr[i]); 
    _   }
  _     System.out.println(S);
 _     _// check each possible sequence_from the_start 
   _  _ //_then update optimal_length 
    _  _for (int i = 0; i_<_n; ++i) 
___ _  _{_
 __     __  System.out.println("ARR " + i);

 _   __   _ // if current element_is the starting 
  _ _ _     // element of a sequence 
_     _   _ if_(!S.contains(arr[i]-1))_
  __ _      {_
 _     _   __   //System.out.println("INSIDE.CONTAINS");
  _     _    ___// Then check for next_elements in the 
  _  _      __  // sequence 
 __     ___    _int j = arr[i]; 
 _        _  _  int t =_0;
__         _ _  while_(S.contains(j)) { 
       _      _     System.out.println("ANS " + ans);  _       _      
_   __      ____  _ t++;
 _  _ _  _ _  __    if (t > ans ) { Seq.add(j);}
       _     _    __j++; 
 _   _       _     // System.out.println("T " +_t);

_ _   _ _ _  _ _ _// _System.out.println("SEQ <<<<<<< " + Seq );
 __        ____ }
 _  _  _  __    // update_ optimal length_if this length 
_         _     // is more 
        _ _   _ if_(ans_< j-arr[i]) {
   _ _       __     ans = j-arr[i]; 
   ___  __     _}__
__     _    } 
 __    _} 
__   _  System.out.println(Seq);
 _      System.out.println(ans);

    __ _return_ans;

A:

That_seems_like a rather roundabout_way of determining a sequence.
I believe one of your flaws is here:
// if current element_is_the starting 
// element of_a sequence 
if (!S.contains(arr[i]-1)) 
{ 

This_is_definitely flawed.
Let's say you_have the input sequence {1,3,5,2,4,6}.  There are_no sequences of 2 or_more in that list._ However, inputs from 2 to 6 would pass your test of S.contains(arr[i]-1