Problems178
Search for a command to run...
First index whose value is strictly greater than x
Try your own input
Change the array and replay the algorithm from step one.
Current step
Upper bound of 2: the index of the first element strictly greater than 2. Note the single character of difference from lower bound — > rather than ≥ — which is what makes it skip past equal values.
Brute Force
1function upperBound(nums, x) {2 const n = nums.length;//x: 2n: 4ans: —3 for (let i = 0; i < n; i++) {4 // First element strictly greater than x5 if (nums[i] > x) {6 return i;7 }8 }9 // Nothing is greater10 return n;11}