Implemented the Magic ExchangeArray function