Solve a medium-to-hard array manipulation problem under strict time and space complexity requirements.