Skip to content

ORIGINAL CODING QUESTION

Mountain summit index

Values strictly increase then strictly decrease, with the summit strictly inside the array. Return its zero-based index.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n integer values. Print one integer as described.

Constraints

3 ≤ n ≤ 200; -100 ≤ value ≤ 100; exactly one interior summit.

Example 1

Input

5 1 3 7 4 2

Output

2

The summit is at index 2.

Example 2

Input

3 0 2 1

Output

1

The summit is at index 1.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Use the slope between mid and mid+1.

Hint 2

An ascending slope means the summit lies farther right.

Hint 3

On a descending slope keep mid as a possible summit.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →