lets say you have 7 elements in list. [10,11,12,13,14,15,16] and if you get 1-based index from reverse you get [-7,-6,-5,-4,-3,-2,-1]. so whenever you give negative index value in slicing like [-4:] it just get you all values from -4 index to end. so in this case [13,14,15,16]. You can read how slicing works in python lists. that will give you all others operations. In general [Initial:end:indexjump]. And if you give any negative numbers, then its just reversed 1 based index.
You can do it in O(1) time O(N) space using a queue.
Short and clear explanation!
hi, please why is it -self.size
lets say you have 7 elements in list. [10,11,12,13,14,15,16] and if you get 1-based index from reverse you get [-7,-6,-5,-4,-3,-2,-1]. so whenever you give negative index value in slicing like [-4:] it just get you all values from -4 index to end. so in this case [13,14,15,16].
You can read how slicing works in python lists. that will give you all others operations. In general [Initial:end:indexjump].
And if you give any negative numbers, then its just reversed 1 based index.
Great!