Completing this problem?

can someone solve this?

Complete the longestRun method as described. Given an array of ints, determine the length of the longest “run” of values contained therein. A “run” is a group of identical values that are adjacent to each other in the array.

int longestRun(int[] nums)

Examples:
longestRun([2,3,4,5,3]) --> 1
longestRun([3,1,1,1,1,2,2]) --> 4
longestRun([6,5,99,99,3,3]) --> 2

Is this a homework question?

yeah, I jus didn’t know how.

I think there are guidelines in this forum about answering homework questions. Please read: Under Guidelines—Tips for Asking Questions.

1 Like

You should look at each element in the list in order.

Then check if the element continues a run.

If it does, the current run you’re looking at is one longer.

If it doesn’t, you’re starting a new run. What will you need to remember at this point? How will you remember that?

… try working out how you, as a person, would solve this problem. Come up with a list of steps that you can explain. Then write code that does those steps.

2 Likes