class Solution {
public:
int findUnsortedSubarray(vector<int>& nums) {
vector<int> nums2 = nums;
int n = nums.size(), left = 0, right = nums.size() - 1;
sort(nums.begin(), nums.end());
for(left = 0; left < n; ++left) {
//cout << "left: "<< left << ", " << nums[left] << ", " << nums2[left] << endl;
if (nums[left] != nums2[left]) break;
}
for(right = nums.size() - 1; right >= left; right--) {
cout << "right: "<< left << ", " << nums[right] << ", " << nums2[right] << endl;
if (nums[right] != nums2[right]) break;
}
return right - left + 1;
}
};