Solved Partition Array Problem with O(n) space