class Solution {
public int partitionDisjoint(int[] nums) {
int[] leftMaximum = new int[nums.length], rightMinimum = new int[nums.length];
leftMaximum[0] = nums[0]; for (int i = 1; i < nums.length; i++) leftMaximum[i] = Math.max(leftMaximum[i-1], nums[i]);
rightMinimum[nums.length-1] = nums[nums.length-1]; for (int i = nums.length-2; i>=0; i--) rightMinimum[i] = Math.min(rightMinimum[i+1], nums[i]);
for (int i = 0; i+1<nums.length; i++) if (leftMaximum[i]<=rightMinimum[i+1]) return i+1;
return -1;
}
}