in java Longest Equal Sequence Please write the function lon
in java Longest Equal Sequence: Please write the function longestSequence(int[] arr): Given an array of integers, return the length of the longest contiguous sequences of equal values.
Example:
 Input: [0, 1, -2, 4, 4, 3]
 Output: 2
 Input: [0, 1, 1, 0, 0, 0]
 Output: 3
Solution
PROGRAM
public class LongSeq
 {
    public static void main(String args[])
    {
    int a[]={1,1,2,3,4,5,5,5,7,8};
    int max=0,count=1;
       for(int i=0;i<a.length-1;i++)
        {
            if(a[i]==a[i+1])
            {
                count+=1;
                if (count > max)
max=count;
              
                               
            }
            else
            {
                if (count > max)
max=count;
               count=1;
            }
       
        }
   System.out.print(\"Input:\");
    System.out.print(\"[ \");
    for(int i=0;i<a.length;i++)
        System.out.print(\" \"+a[i]);
    System.out.print(\" ]\");
    System.out.println();
    System.out.println(\"Output: \"+max);
   }
 }          
SAMPLE OUTPUT
Input:[ 1 1 2 3 4 5 5 5 7 8 ]
 Output: 3
![in java Longest Equal Sequence: Please write the function longestSequence(int[] arr): Given an array of integers, return the length of the longest contiguous se in java Longest Equal Sequence: Please write the function longestSequence(int[] arr): Given an array of integers, return the length of the longest contiguous se](/WebImages/37/in-java-longest-equal-sequence-please-write-the-function-lon-1110792-1761588922-0.webp)
