Solution for array duplicate problem