Another option would be to pass in boolean so that we do not need to create the temporary array.