JSFiddle - React, Tailwind, and code Playground

check test case and redo the pivot finder using template 2 (see comments). this will find the first element AFTER pivot, which is what we're looking for

by Yurii Predborskyi

JavaScript

/**
 * @param {number[]} nums
 * @return {number}
 */
var findMin = function(nums) {
    let res;
    let left = 0;
    let right = nums.length - 1;
    if (left === right) {
        return nums[0];
    }
    while (left !== right) {
        let mid = Math.floor((left + right) / 2);
        if (nums[mid] > nums[right]) {
            left = mid + 1;
        } else if (nums[mid] < nums[left]) {
            right = mid;
        } else if (mid === left) {
            return nums[findPivot(mid)];
        } else {
            right = mid;
        }
    }
    return nums[findPivot(left)];
};