Tap here to switch tabs
Problem
Submissions

Problem: Smallest Stable Index II

Try to solve the Smallest Stable Index II problem.

Statement

You are given an integer array nums and an integer k.

For each index i where 0≤i<0 \leq i < nums.length, the instability score is defined as the difference between the maximum value in the subarray from index 00 to i inclusive and the minimum value in the subarray from index i to nums.length −1- 1 inclusive.

Return the smallest index i such that the instability score at index i is less than or equal to k. If no such index exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Smallest Stable Index II

Try to solve the Smallest Stable Index II problem.

Statement

You are given an integer array nums and an integer k.

For each index i where 0≤i<0 \leq i < nums.length, the instability score is defined as the difference between the maximum value in the subarray from index 00 to i inclusive and the minimum value in the subarray from index i to nums.length −1- 1 inclusive.

Return the smallest index i such that the instability score at index i is less than or equal to k. If no such index exists, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9