The sliding window defined by RANGE BETWEEN N FOLLOWING and N PRECEDING does not add/remove rows in the correct order.
The issue lies within the last partition. The removal of elements from the window is wrong. It removes an element 1 row after the one that should be removed.
The problem lies in the fact that the removal of elements from the sliding window is done incorectly.
from [32, 64, 128], we should add the row containing 16 and remove the row containing 32. Instead, when calling the remove() function for the window function, the current item points to row with the value of 64. Thus we remove 64 and get [32, 128, 16].
Again the same problem continues for the next row. Instead of removing the value 64, we are removing the value 128 (the row after the correct value).