Longest subarray of equal integers

Report a typo

You have an array of integers. Your task is to find the length of the longest subarray that contains only equal integers. For example, if the array is [3,3,3,1,5,5,5,5,2,6][3, 3, 3, 1, 5, 5, 5, 5, 2, 6], the longest subarray of equal integers is [5,5,5,5][5, 5, 5, 5], with a length of 44.

Please fill in the blanks below to complete the pseudocode (1-based index):

I encourage you to implement the pseudocode in any of your favorite programming languages and post it in the comment box below.

Fill in the gaps with the relevant elements
function longestSubarray(array):
    start = 1
    longestLength = 0
    for end from 2 to length(array):
        if :
            longestLength = 
            
return longestLength
array[end] = array[start]max(longestLength, end - start)start = endarray[end] != array[start]

Create a free account to access the full topic