Modified algorithm by creating a sub-array copy