You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vector<int> findIndices(vector<int>& nums, int indexDifference, int valueDifference) {
for (int i = 0, mx_i = 0, mn_i = 0; i + indexDifference < size(nums); ++i) {
if (nums[i] > nums[mx_i]) {
mx_i = i;
} else if (nums[i] < nums[mn_i]) {
mn_i = i;
}
// we don't need to add abs for the difference since
// - if nums[mx_i]-nums[i+indexDifference] < 0, then checking nums[i+indexDifference]-nums[mn_i] >= -(nums[mx_i]-nums[i+indexDifference]) > 0 can cover the case
// - if nums[i+indexDifference]-nums[mn_i] < 0, then checking nums[mx_i]-nums[i+indexDifference] >= -(nums[i+indexDifference]-nums[mn_i]) > 0 can cover the case
if (nums[mx_i] - nums[i + indexDifference] >= valueDifference) {
return {mx_i, i + indexDifference};
}
if (nums[i + indexDifference] - nums[mn_i] >= valueDifference) {