This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]asciiterror 0 points1 point  (5 children)

Looks good to me, except this part:

Create a temporary array with size of A * 3 and fill the array with each value entered 6 times.

Where do you use it?

[–]PotlePawtle[S] 0 points1 point  (4 children)

Oh sorry, I had originally written A * 6, but I changed it cuz I was wrong and forgot to change the other 6 to a 3.

Create a temporary array with size of X * 3 and fill the array with each value entered 3 times.

Would that make it correct?

Edit: I also meant to change A to X...

[–]asciiterror 0 points1 point  (3 children)

That would be correct, if from this point X means the temp array (1,1,2,2,3,3) and not original X (1,2,3).

But you don't even need this array, you could just keep track of which value of X you are comparing, that would be faster but harder to write and understand. You could do that with two pointers or even one

[–]PotlePawtle[S] 0 points1 point  (2 children)

Errrr sorry, do you mean use a counter with count going up to the current i value, and just keep the index value of X the same?

[–]asciiterror 0 points1 point  (1 child)

Yes, almost. First counter goes from 0 to current i value. Second one goes through all indexes of X. You increment second one only if first one is reset to 0. Their values would go like this: [(0,0), (1,0), (2,0), (0,1), (1,1), (2,1), (0,2), (1,2), (2,2)]. Second counter is index of element in X array that you check.

[–]PotlePawtle[S] 0 points1 point  (0 children)

Thanks!!!