codekofi
← All problems

Problem 37

Medium

1 · Worked examples

0 / 4

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 4 outputs correctly.

The accepted solution

1int solution(const vector<int>& nums) {
2
3 int n = nums.size();
4 int lo = 0;
5 int hi = n - 1;
6
7 while (lo < hi) {
8
9 int mid = lo + (hi - lo) / 2;
10
11 if (nums[mid] > nums[hi]) {
12 lo = mid + 1;
13 } else {
14 hi = mid;
15 }
16 }
17
18 return nums[lo];
19}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.