+ 1
Define a function named longest_duplicates that returns the length of the longest sub-array of duplicates in a given sort array.
Need urgent help!!
2 odpowiedzi
+ 2
send the sorted array in as a parameter.
2 variables. one for the longest count.
one for the current count
both start at 0
start at index 0 and walk until size-1, for last index
make current increase as long as index x+1 is the same as x.
if the current count ever exceeds the longest count, After the indexes are different numbers, re assign the length.
you could also keep a variable for number or first index of the longest. as a reference.
hope this helps!!
0
Thank you very much.