I am trying to find something equivalent remove_range(which, of course, does not exist), as shown below. There seems to be no easy way to implement this functionality.
a = [0,2,8,2,4,5,]
b = a.remove_range(1,2)
b = a.remove_range(3,4)
Before submitting a solution, please check at least two cases :)
Assume that the size of the range is M, this operation should take O (1) time and O (NM) time complexity.
EDIT: I see people keep posting a - a[range]. But this is not true, that is, delete elements in [range], and not delete an element belonging to a range.
a - a[1..2]will return [0, 4, 5]. However, we want to save the 3rd element, which 2.
source
share