why do you need a[i]!= 0 when a[i] is forced between 10 and 20?
what was that put in to accomplish?
I have no idea how your code is trying to solve the problem.
get all the numbers.
then loop after that:
for all the numbers
temp = current number //not required, you can use array[index], helps pseudocode to have it
count = 1
whileindex = current index+1 (for loop counter)
while(current index is valid and array[whileindex++] == temp) count ++;
//count is also not required as you can take difference in where you land vs where you started but its easier to understand this way
store it -- if count == 1 save number, else save number and count both to target
for loop index moved to correct position here CRITICAL step, you don't want 2 2 2 2 to give you 2 -4 2-3 2-2 2 :P
something like that.
remember that rle isnt aware of anything but blocks.
2 2 2 7 2 2 2
is 2 -3 7 2 -3
your code seems to get 2 -6 count and that won't work
Why are you limiting the input to 10 to 20 in the first place? The example has 8 and 65 in it. Presumably you just need to limit it to non-negative numbers.
I am saying I don't think your logic is correct.
your code counts all the instances of the same number. I am going out on a limb here and saying that
2 2 2 7 2 2 2
is
2 -3 7 2 -3 'compressed', right?
your code counts 6 2s, not the groups.
I gave you the straight up brute force approach. once more,
loop over the values
while the current value is == to the previous one, count them up
store the result in the target
so you need to trigger your code off when the data changes, eg
2 2 2 7 3 1 4 1 5
starts out.
current is 2.
count is 1.
move to next. is the next value same as current? yes. increment count.
move to next. is the next value same as current? yes. increment count.
now the next value is 7. its not equal to current. save current (still 2) and count (now 3).
result now has 2 -3 in it.
current becomes 7. count resets to 1.
move to next... 3 is not the same store 7. count is one, do not store 1s. result is now 2 -3 7
current becomes 3...
so its a 3 or 4ish if statements in your loop and a number of variable to keep track of, but its straightforward ...