int k = idx; while (k + 1 < n && nums[k] == nums[k + 1]) k++;
int k = idx; while (k < n && nums[k] == nums[idx]) k++;