Accepted solution for removing element from an array inplace