I was assigned a programming problem for homework, and I am at a stand-still. I have searched for hours today trying to find an answer, and it seems like it\'s never been asked
Think about how you'd do this with pen and paper.
The fact that the array is sorted allows you to optimize this algorthm by looking for the shortest consecutive run of equal numbers. That means you can do this in a single pass, with O(1)
auxiliary memory.